home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Graphics / SMan / WarpOS / Source / SManWOS.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-28  |  59.8 KB  |  2,558 lines

  1. #include    <clib/all_protos.h>
  2. #include    <math.h>
  3. #include    <float.h>
  4. #include    <string.h>
  5. #include    <exec/memory.h>
  6. #include    <exec/tasks.h>
  7. #include    <iffp/packer.h>
  8. #include    <iff/iff.h>
  9. #include    <iff/ilbm.h>
  10. #include    <exec/execbase.h>
  11. #include    <graphics/gfxbase.h>
  12. #include    <devices/timer.h>
  13. #include    <utility/tagitem.h>
  14.  
  15.  
  16. #include    <powerpc/powerpc.h>
  17. #include    <powerpc/tasksPPC.h>
  18. #include    <clib/powerpc_protos.h>
  19.  
  20. #include    <clib/cybergraphics_protos.h>
  21. #include    <cybergraphx/cybergraphics.h>
  22.  
  23.  
  24. #define SETRGB(s,cn,r,g,b)     SetRGB4(&((s)->ViewPort),cn,r,g,b)
  25. #define MemMode MEMF_FAST | MEMF_CLEAR | MEMF_REVERSE
  26.  
  27.  
  28. extern void FndFnc(void);
  29. ULONG    TimerHi,TimerLo;
  30. extern void Save(void);
  31.  
  32.  
  33. extern void UseLibP2(double);
  34. extern void UseLibP3(double);
  35. extern void UseLibP4(double);
  36. extern void UseLibP5(double);
  37. extern void UseLibP6(double);
  38. extern void UseLibP7(double);
  39.  
  40. UWORD *OldColorTable,*NewColorTable;
  41. ULONG    ThisMode,TableSize;
  42. ULONG    BFactor = 16777216;
  43. ULONG ColorsOld[4];
  44. ULONG ColorsNext[4];
  45. ULONG *LPixelBuf;
  46. UBYTE *WindowBuf;
  47.  
  48.  
  49. UWORD *POTGOR;
  50. UBYTE *DDRAV,*SDRV,*PDRAAV;
  51.  
  52.  
  53. struct Library *WarpBase;
  54. struct Library *TimerBase;
  55. struct MsgPort *TimerPort;
  56. struct timerequest *tr;
  57. struct    TaskPPC *MyTask;
  58.  
  59. UBYTE *PixelBuf;
  60. char CPUStrBuf[256];
  61. char MyStringBuf[256];
  62.  
  63. UWORD ShortOld[4];
  64. UWORD ShortNext[4];
  65. UBYTE OldColors[4];
  66. UBYTE NextColors[4];
  67. UBYTE *ColorTable32;
  68.  
  69. UWORD    Color,LastMax;
  70. ULONG NumColors,TopCol,Secs,Micros,LSec;
  71. double ElTime;
  72. int    NumPubs,BPP,MWWidth;
  73. int    PalSize;
  74. UBYTE *BoardMem;
  75. extern int Selected;
  76. int    TotNum;
  77.  
  78. SHORT    VertPos;
  79. SHORT    PolyTab[10];
  80. SHORT    *PolyPnt;
  81. SHORT    DeltaX,DeltaY; SHORT    x1,y1,x2,y2;
  82. SHORT    Power;
  83. double    PowerF,DeltaP;    /*Fractional power */
  84. double    DX;
  85. double    MaxErr;        /*Maximum error on ArcTan */
  86. struct CyberModeNode *CyberTags;
  87.  
  88. double Two,Limit,XWidth,XHeight,Pi,XCenter,YCenter,HWidth,HHeight,Factor,Pi,TwoPi,PowerN;
  89. double LastX,LastY,LastFactor,PiD2;
  90. LONG    xtemp,ytemp,MaxCnt,CurCnt,XC,YC,LeftEdge,RightEdge,NearEdge,FarEdge;
  91. ULONG    MltPlr;
  92. ULONG    *PlnPtr;
  93. LONG     BLeft,BTop,InfBLeft,InfBTop;
  94. WORD    WWidth,WHeight,WDepth,SDepth,PFMT;
  95. BPTR    FileHandle;
  96. UWORD    FontHeight,MenWidth,LeftPos;
  97. SHORT    TFHeight;
  98. USHORT    IWHeight,IWWidth,TwoSpace;
  99. UWORD    LinBuf[1600];
  100. BOOL IsChunk,IsVilScreen,IsCyberScreen,SaveIFF;
  101.  
  102.  
  103. struct TextAttr        DefBold;
  104. struct    TextAttr    *DefFont;
  105. struct    TextFont    *DFont;
  106. struct    TextFont    *BFont;
  107. struct TextFont *CWFont;
  108.  
  109. struct    TextExtent    TextUsed;
  110.  
  111. struct TextAttr topaz8 =
  112.   {
  113.   (STRPTR)"topaz.font",    /* ta_Name */
  114.   8,    /* ta_YSize */
  115.   FS_NORMAL,    /* ta_Style */
  116.   0x0    /* ta_Flags */
  117.   };
  118.  
  119.  
  120. struct TextAttr topaz9 =
  121.   {
  122.   (STRPTR)"topaz.font",    /* ta_Name */
  123.   9,    /* ta_YSize */
  124.   FSB_BOLD,    /* ta_Style */
  125.   0x0    /* ta_Flags */
  126.   };
  127.  
  128.  
  129. #define    ChdFlg    DefFlg | CHECKIT | CHECKED
  130. #define    ChkFlg    DefFlg | CHECKIT
  131.  
  132. ULONG    CmpFlg    = MOUSEBUTTONS | MENUPICK ;
  133. ULONG    MyFlag     =    NOCAREREFRESH|REPORTMOUSE|BORDERLESS;
  134. ULONG    MenFlg     =    MENUENABLED | MIDRAWN;
  135. ULONG    DefFlg     =    ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHCOMP;
  136.  
  137. extern    struct DosLibrary *DOSBase;
  138. struct GfxBase *GfxBase;
  139. struct Library *DiskfontBase;
  140. struct IntuitionBase *IntuitionBase;
  141. struct Library *GadToolsBase;
  142. struct Library *UtilityBase;
  143. struct CyberGfxBase *CyberGfxBase;
  144. struct Library *CyberIntuit;
  145. struct Library *CyberLayer;
  146. struct Library *CgxSystemBase;
  147.  
  148. extern    struct ExecBase    *SysBase;
  149. struct    Gadget    *GadStuff;
  150. struct    NewScreen    ns;
  151. struct    NewWindow    nw;
  152. BYTE    CurrentXOffset;
  153. BYTE    CurrentYOffset;
  154. UBYTE    Title[] = " Information about this Fractal";
  155. UBYTE    TitleM[] = " Exploring the Julia Sets";
  156.  
  157. UBYTE    *WindowName;
  158. SHORT    SWidth,SHeight,CPU;
  159. USHORT    MyView,SysFlag,MenVal;
  160. ULONG    IMClass;
  161. struct    Screen    *WBScreen;
  162. struct    Window    *InfoWindow;
  163. struct    Window    *IntWindow;
  164.  
  165. struct    MsgPort    *MyPort,*IntPort,*MWPort;
  166. struct    RastPort    *WBRast,*CWRast,*MWRast,*WBSRast;
  167. struct    ViewPort    VPorta,VPortb;
  168. struct    Preferences    MyNewPrefs,*CurPrefs;
  169. struct    Menu        ProjMenu,CountMenu,ChangeMenu,PowerMenu;
  170. struct    MenuItem    *MIStruct;
  171. struct    IntuiText    *ITStruct;
  172.  
  173. /*    The following structures are for temporary non-displayable rastors for use in
  174. saving the image to an iff file */
  175. struct RastPort VTmpRast,MainWRast;
  176. struct BitMap *TmpBitMap,*MWBitMap;
  177. struct BitMap *NWBitMap;
  178. struct RastPort NWRast;
  179.  
  180.  
  181. struct    MenuItem    MI11,MI12,MI13,MI14,MI15,MI16,MI17;
  182. struct    MenuItem    MI31,MI32,MI33,MI34,MI35,MI36;
  183. struct    MenuItem    MI41,MI42,MI43,MI44,MI45,MI46,MI47;
  184. struct    MenuItem    MI21,MI22,MI23,MI24,MI25,MI26;
  185. struct    IntuiText    IT11,IT12,IT13,IT14,IT15,IT16,IT17;
  186. struct    IntuiText    IT31,IT32,IT33,IT34,IT35,IT36;
  187. struct    IntuiText    IT41,IT42,IT43,IT44,IT45,IT46,IT47;
  188. struct    IntuiText    IT21,IT22,IT23,IT24,IT25,IT26;
  189. struct    IntuiText    DummyText;
  190.  
  191. struct    PLANEPTR    *PlanePtrA;
  192. UBYTE    PalOpt;
  193. UBYTE    Comma[] = {0x2c};
  194. static    char    Mesag3[]    = "System Hardware: ";
  195. static    char    Mesag4[]    = "Use the menu options on the Julia Window to change the following parameters!";
  196. static    char    Mesag5[]    = "Click on the Close Gadget to bring the Julia Window forward!";
  197. static    char    Mesag6[]    = "(Note:  This window won't be closed, but perhaps hidden.)";
  198. static    char    Mesag7[]    = "To bring the Information Window forward, select 'About' from the Project menu!";
  199. static    char    Mesag8[]    = "The Window 'Exploring the Juila Sets' is on the screen                       ";
  200. static    char    ScrMsg[]    = "Window center is at ";
  201. static    char    MandMsg[]    = "The algorithm is z  + z -> z, where z = x + iy.";
  202. static    char    MandMsgG[]    = "The algorithm is z   + z -> z, where z = x + iy.";
  203. static    char    MandMsgP[]    = "The algorithm is z                 + z -> z, where z = R*exp(i0).";
  204. static    char    MandMsgPG[]    = "The algorithm is z                  + z -> z, where z = R*exp(i0).";
  205. static    char    ChpMsg[]    = "Chip Memory Free = ";
  206. static    char    ChpEnd[]    = "                ";
  207. static    char    FstMsg[]    = "Fast Memory Free = ";
  208. static    char    FstEnd[]    = "                        ";
  209. static    char    WdtMsg[]    = "Image Width =  ";
  210. static    char    WdtEnd[]    = "        ";
  211. static    char    HgtMsg[]    = "Image Height = ";
  212. static    char    HgtEnd[]    = "        ";
  213. /*
  214. static    char    MagMsg[]    = "Magnification = ";
  215. static    char    MagEnd[]    = "                  ";
  216. */
  217.  
  218. static    char    MagMsg[]    = "Magnification =               ";
  219.  
  220. static    char    XPos[]        = "x = ";
  221. static    char    XPsEnd[]    = "                              ";
  222. static    char    YPos[]        = "y = ";
  223. static    char    YPsEnd[]    = "                              ";
  224. static    char    CntMsg[]    = "Maximum Count = ";
  225. static    char    CntEnd[]    = "             ";
  226. static    char    St882[]        = " 68882";
  227.  
  228. /*extern void FncFnd(void);*/
  229.  
  230.  
  231. WORD GetLength(UBYTE *);
  232. WORD GethPos(UBYTE *);
  233. WORD LengthDescript(void);
  234. void InitVS(void);
  235. void LibsOpen(void);
  236. void TrueToggle(UWORD,UWORD,UWORD,UWORD);
  237. void LibsClose(void);
  238. void LineToggle(UWORD,UWORD,UWORD,UWORD);
  239. void WriteStuff(void);
  240. void WindowSet(void);
  241. void CheckMsg(void);
  242. void CheckIntMsg(void);
  243. void ITInit(struct IntuiText *,UBYTE *);
  244. void ErrorDisplay(void);
  245. void MIInit(struct MenuItem *,struct MenuItem *,SHORT,BYTE,APTR,SHORT);
  246. void CheckCOPP(void);
  247. void MenuInit(struct Menu *,struct Menu *,BYTE *,SHORT,SHORT);
  248. void PowerChange(void);
  249. void MyFill(UWORD,UWORD,UWORD,UWORD,UWORD);
  250. void DescribeSystem(void);
  251. void ScreenSet(void);
  252. void CountChange(void);
  253. void ScreenClose(void);
  254. void Palette32(void);
  255. void ScreensClose(void);
  256. void GetWindowSize(void);
  257. int  OpenWrite(UBYTE *);
  258. void FullSurface(void);
  259.  
  260.  
  261. int  WriteFile(UBYTE *,ULONG);
  262. void Status(void);
  263. void CloseWrite(void);
  264. void RestoreOrigColors(void);
  265. int ShowPalette(void);
  266. UBYTE *GetColors(UBYTE *,ULONG);
  267. ULONG LongSwap(ULONG);
  268. void MySetRGB(SHORT,USHORT);
  269.  
  270. void StorePalette(UBYTE *);
  271.  
  272. void DisLine(struct RastPort *,char *,int);
  273.  
  274. struct timeval CurTime;
  275.  
  276.  
  277. void InitVS(void)
  278. {
  279.     BPP = GetCyberIDAttr(CYBRIDATTR_BPPIX,ThisMode);
  280.  
  281.     SDepth = GetCyberIDAttr(CYBRIDATTR_DEPTH,ThisMode);
  282.     SWidth = GetCyberIDAttr(CYBRIDATTR_WIDTH,ThisMode);
  283.     SHeight = GetCyberIDAttr(CYBRIDATTR_HEIGHT,ThisMode);
  284.     PFMT = GetCyberIDAttr(CYBRIDATTR_PIXFMT,ThisMode);
  285. }
  286.  
  287.  
  288. struct timerequest *CreateTimer(ULONG unit)
  289. {
  290. LONG error;
  291. struct timerequest *TimerMsg;
  292.  
  293.     TimerPort = CreatePort("MyTimer",32);
  294.     TimerMsg = (struct timerequest *)    CreateIORequest(TimerPort,sizeof(struct timerequest ));
  295.     if (!TimerMsg) return(NULL);
  296.     error = OpenDevice("timer.device",UNIT_MICROHZ,(struct IORequest *) TimerMsg,0L);
  297.     if (error)    {
  298.         DeletePort(TimerPort);
  299.         return(NULL);
  300.         }
  301.     return(TimerMsg);
  302. }
  303.  
  304.  
  305. void OpenTimer(void)
  306. {
  307.     tr = CreateTimer(1);
  308.     TimerBase = (struct Library *)tr->tr_node.io_Device;
  309. }
  310.  
  311. void CloseTimer(void)
  312. {
  313.     if (TimerPort) DeletePort(TimerPort);
  314.     if (TimerBase) TimerBase = (struct Library *)(-1);
  315. }
  316.  
  317.  
  318. void TrueToggle(x,y,xe,ye)
  319. UWORD x, y, xe, ye;
  320. {
  321. ULONG tmpVal;
  322. ULONG color;
  323. UWORD Lft,Top;
  324.     Lft = IntWindow->LeftEdge;
  325.     Top = IntWindow->TopEdge;
  326.     if (y > ye)    {
  327.         tmpVal = y;
  328.         y = ye;
  329.         ye = tmpVal;
  330.         }
  331.     if (y == ye)    {
  332.         if (x > xe) {
  333.             tmpVal = x;
  334.             x = xe;
  335.             xe = tmpVal;
  336.             }
  337.         while(x < xe) {
  338.             color = ReadRGBPixel(&WBScreen->RastPort,x + Lft,y + Top);
  339.             color = 0xffffff - color;
  340.             color = color & 0xffffff;
  341.             WriteRGBPixel(&WBScreen->RastPort,x+Lft,y+Top,color);
  342.             x++;
  343.             }
  344.         }
  345.     else while (y < ye)    {
  346.         color = 0xffffff - ReadRGBPixel(&WBScreen->RastPort,x + Lft,y + Top);
  347.         color = color & 0xffffff;
  348.         WriteRGBPixel(&WBScreen->RastPort,x+Lft,y+Top,color);
  349.         y++;
  350.         }
  351. }
  352.  
  353. void LineToggle(x,y,xe,ye)
  354. UWORD x, y, xe, ye;
  355. {
  356. UWORD tmpVal;
  357. UBYTE color;
  358.     if (SDepth > 8)    {
  359.         TrueToggle(x,y,xe,ye);
  360.         return;
  361.         }
  362.     if (y > ye)    {
  363.         tmpVal = y;
  364.         y = ye;
  365.         ye = tmpVal;
  366.         }
  367.     if (y == ye)    {
  368.         if (x > xe) {
  369.             tmpVal = x;
  370.             x = xe;
  371.             xe = tmpVal;
  372.             }
  373.         while(x < xe) {
  374.             color = ReadPixel(CWRast,x,y);
  375.             color = 255 - color;
  376.             SetAPen(CWRast,color);
  377.             WritePixel(CWRast,x,y);
  378.             x++;
  379.             }
  380.         }
  381.     else while (y < ye)    {
  382.         color = 255 - ReadPixel(CWRast,x,y);
  383.         SetAPen(CWRast,color);
  384.         WritePixel(CWRast,x,y);
  385.         y++;
  386.         }
  387. }
  388.  
  389. void TruePixel(UWORD x,UWORD y,ULONG color)
  390. {
  391. ULONG *DstBuf,*Src;
  392.     DstBuf = (ULONG *)WindowBuf;
  393.     DstBuf = DstBuf + WWidth*(ULONG)y;
  394.     DstBuf = DstBuf + (ULONG)x;
  395.     Src = (ULONG *)ColorTable32 + color;
  396.     *DstBuf = *Src;
  397. }
  398.  
  399. void SetTrueColor(UWORD x, UWORD y, ULONG color)
  400. {
  401. ULONG *ColLng;
  402. UWORD Lft,Top;
  403. UBYTE *Src;
  404.     Lft = IntWindow->LeftEdge;
  405.     Top = IntWindow->TopEdge;
  406.     Lft = Lft + BLeft;
  407.     Top = Top + BTop;
  408.     if (x  + BLeft >= IntWindow->Width - IntWindow->BorderRight) return;
  409.     if (color < 0xfffe)    color = color + 4;
  410.     Src = ColorTable32 + 4*color;
  411.     ColLng = (ULONG *)Src;
  412.     *LPixelBuf++ = *ColLng;
  413. }
  414.  
  415. void ReadPackedLine(struct Screen *s,UWORD xs,UWORD y,UWORD lWidth,UBYTE *Dest)
  416. {
  417. UWORD pCnt;
  418.     register ULONG    offset = (s->Width*y + xs);
  419.     pCnt = 0;
  420.     while (pCnt < lWidth)    {
  421.         *Dest++ = *(BoardMem+offset);
  422.         offset++;
  423.         pCnt++;
  424.     }
  425. }
  426.  
  427. void ITInit(Item,NamePtr)
  428. struct    IntuiText    *Item;
  429. UBYTE    *NamePtr;
  430. {
  431.     Item -> IText = NamePtr;
  432.     Item -> BackPen = 0;
  433.     Item -> FrontPen = 3;
  434.     Item -> DrawMode = JAM1;
  435. }
  436.  
  437. void MIInit(Item,NxtItem,TEdge,Cmd,ITItem,Width)
  438. struct    MenuItem    *Item,*NxtItem;
  439. APTR    ITItem;
  440. SHORT    TEdge,Width;
  441. BYTE    Cmd;
  442. {
  443.     Item -> Command = Cmd;
  444.     Item -> TopEdge = TEdge;
  445.     Item -> NextItem = NxtItem;
  446.     Item -> ItemFill = (APTR)ITItem;
  447.     Item -> Flags = (USHORT)DefFlg;
  448.     Item -> Height = FontHeight;
  449.     Item -> Width = Width;
  450. }
  451.  
  452. void MenuInit(MenuStruct,NxtMenu,NamePtr,LEdge,MWidth)
  453. struct Menu    *MenuStruct,*NxtMenu;
  454. SHORT    LEdge,MWidth;
  455. BYTE    *NamePtr;
  456. {
  457.     MenuStruct -> NextMenu = NxtMenu;
  458.     MenuStruct -> Width = MWidth;
  459.     MenuStruct -> Height = FontHeight;    /*9;*/
  460.     MenuStruct -> LeftEdge = LEdge;
  461.     MenuStruct -> TopEdge = 0;
  462.     MenuStruct -> MenuName = NamePtr;
  463.     MenuStruct -> Flags = MenFlg;
  464.  
  465. }
  466.  
  467.  
  468. void MyFill(color,xl,yt,xr,yb)
  469. UWORD color,xl,yt,xr,yb;
  470. {
  471. UWORD x,y;
  472.     x = xl;
  473.     y = yt;
  474.     while (y < yb) {
  475.         while (x < xr) {
  476.             TruePixel(x,y,(ULONG)color);
  477.             x++;
  478.             }
  479.         x = xl;
  480.         y++;
  481.         }
  482. }
  483.  
  484.  
  485. ULONG    LngColor(int TableCnt)
  486. {
  487. ULONG RGBColor;
  488. UBYTE *Src;
  489. UBYTE Red, Green, Blue;
  490.     Src = (UBYTE *)NewColorTable;
  491.     Src = Src + 4*TableCnt;
  492.     Blue = *Src++;
  493.     Green = *Src++;
  494.     Red = *Src++;
  495.     RGBColor = (ULONG)Red;
  496.     RGBColor <<= 8;
  497.     RGBColor = RGBColor | (ULONG)Green;
  498.     RGBColor <<= 8;
  499.     RGBColor = RGBColor | (ULONG)Blue;
  500.     return(RGBColor);
  501.  
  502. }
  503.  
  504. int ShowPicPalette(void)
  505. {
  506. int TmpCol,TopCol;
  507. UWORD xPos,yPos,deltaX,deltaY;
  508.     if (BPP == 1)    {
  509.         yPos = ShowPalette();
  510.         return(yPos);
  511.     }
  512.     deltaX = 4;
  513.     deltaY = 4;
  514.     TmpCol = 0;
  515.     xPos = 20;
  516.     yPos = 2;
  517.     if (BPP == 1) TopCol = 256;
  518.     else TopCol = 3*4096;
  519.     TmpCol = 0;
  520.     while ((TmpCol < TopCol)&&(yPos+20 < IntWindow->Height))    {
  521.         MyFill((UWORD)TmpCol,xPos,yPos,xPos+deltaX,yPos+deltaY);
  522.         xPos = xPos + deltaX;
  523.         TmpCol = TmpCol + 2;
  524.         if (xPos+40 > IntWindow->Width)    {
  525.             xPos = 20;
  526.             yPos = yPos + deltaY;
  527.             }
  528.         }
  529.     return((int)yPos);
  530. }
  531.  
  532. ShowPalette(void)
  533. {
  534. int TmpCol;
  535. UWORD xPos,yPos,deltaX,deltaY;
  536.     deltaX = 16;
  537.     deltaY = 16;
  538.     TmpCol = 4;
  539.     if (NumColors == 16) {
  540.         TmpCol = 0;
  541.         }
  542.     xPos = BLeft;
  543.     yPos = BTop;
  544.     while (TmpCol < TopCol)    {
  545.         SetAPen(CWRast,TmpCol);
  546.         RectFill(CWRast,xPos,yPos,xPos+deltaX,yPos+deltaY);
  547.         if (xPos > WWidth - 80)    {
  548.             xPos = BLeft - deltaX;
  549.             yPos = yPos + deltaY;
  550.             yPos++;
  551.             }
  552.         xPos = xPos + deltaX;
  553.         TmpCol++;
  554.         if (TmpCol == 17) TmpCol = 20;
  555.         }
  556.         SetAPen(CWRast,TmpCol);
  557.         RectFill(CWRast,xPos,yPos,xPos+deltaX,yPos+deltaY);
  558.     return(yPos);
  559. }
  560.  
  561. void ScreenSet()
  562. {
  563. WORD    xPos,yPos;
  564. nw.Title = &TitleM[0];
  565. nw.LeftEdge        =    0;
  566. nw.TopEdge        =    0;
  567.  
  568. nw.Width        =    600;
  569. nw.Height        =    400;
  570.  
  571. nw.Width        =    534;
  572. nw.Height        =    400;
  573.  
  574. nw.Width        =    345;
  575. nw.Height        =    272;
  576.  
  577. nw.BlockPen        =    WBScreen->BlockPen;
  578. nw.DetailPen    =    WBScreen->DetailPen;
  579. nw.IDCMPFlags    =    CmpFlg | IDCMP_NEWSIZE | CLOSEWINDOW ;
  580. nw.Flags        =    WINDOWDRAG|WINDOWDEPTH|SMART_REFRESH|WINDOWCLOSE|ACTIVATE|REPORTMOUSE | WFLG_NEWLOOKMENUS | WFLG_SIZEGADGET;
  581. nw.Screen        =     WBScreen;
  582. nw.FirstGadget    =    NULL;
  583. nw.CheckMark    =    NULL;
  584. nw.BitMap        =    NULL;
  585. nw.MinWidth        =    100;
  586. nw.MinHeight    =    75;
  587. nw.MaxWidth        =    WBScreen->Width;
  588. nw.MaxHeight    =    WBScreen->Height;
  589.  
  590.     if (NumColors == 16)    PalSize = 16;
  591.     else PalSize = TopCol - 6;
  592.     if ((WBScreen->Width < 400)||(WBScreen->Height < 300))    {
  593.         nw.Width        =    WBScreen->Width;
  594.         nw.Height        =    WBScreen->Height;
  595.     }
  596.     IntWindow = (struct Window *)OpenWindow( &nw );
  597.     BLeft = (LONG)IntWindow->BorderLeft;
  598.     BTop = (LONG)IntWindow->BorderTop;
  599.     RightEdge = IntWindow->GZZWidth;
  600.     FarEdge = IntWindow->GZZHeight;
  601.     WWidth = RightEdge;
  602.     WHeight = FarEdge;
  603.     XC = RightEdge/2;
  604.     YC = FarEdge/2;
  605. /* Get associated information about Int window */
  606.     CWRast = IntWindow -> RPort;
  607.     IntPort    = IntWindow -> UserPort;
  608.     MWPort    = IntWindow -> UserPort;
  609.     xPos = BLeft;
  610.     yPos = BTop;
  611.     DummyText.ITextFont = DefFont;
  612.     DummyText.IText = (UBYTE *)"Project__";
  613.     MenWidth = IntuiTextLength(&DummyText);
  614.  
  615.  
  616.     MenuInit(&ProjMenu,&CountMenu,"Project",20,MenWidth);
  617.     DummyText.IText = (UBYTE *)"Redraw(Same P)___________";
  618.     MenWidth = IntuiTextLength(&DummyText);
  619.     ProjMenu.FirstItem = &MI11;
  620.     MIInit(&MI11,&MI12,0,0x41,&IT11,MenWidth);
  621.     MIInit(&MI12,&MI13,FontHeight,0x50,&IT12,MenWidth);
  622.     MIInit(&MI13,&MI14,2*FontHeight,0x53,&IT13,MenWidth);
  623.     MIInit(&MI14,&MI15,3*FontHeight,0x49,&IT14,MenWidth);
  624.     MIInit(&MI15,&MI16,4*FontHeight,0x4c,&IT15,MenWidth);
  625.     MIInit(&MI16,&MI17,5*FontHeight,0x4e,&IT16,MenWidth);
  626.     MIInit(&MI17,0,6*FontHeight,0x51,&IT17,MenWidth);
  627.  
  628.     ITInit(&IT11,"About");
  629.     ITInit(&IT12,"Redraw(Same P)");
  630.     ITInit(&IT13,"Save Image (bmp)");
  631.     ITInit(&IT14,"Save Image (iff)");
  632.     ITInit(&IT15,"Save Parm");
  633.     ITInit(&IT16,"Load Parm");
  634.     ITInit(&IT17,"Quit");
  635.     LeftPos = MenWidth;
  636.     DummyText.IText = (UBYTE *)"Maximum Count__";
  637.     MenWidth = IntuiTextLength(&DummyText);
  638.  
  639.     MenuInit(&CountMenu,&ChangeMenu,"Maximum Count",LeftPos,MenWidth);
  640.     DummyText.IText = (UBYTE *)"Decrease by 8_________";
  641.     MenWidth = IntuiTextLength(&DummyText);
  642.  
  643.     CountMenu.FirstItem = &MI31;
  644.     MIInit(&MI31,&MI32,0,43,&IT31,MenWidth);
  645.     MIInit(&MI32,&MI33,FontHeight,45,&IT32,MenWidth);
  646.     MIInit(&MI33,&MI34,2*FontHeight,0x44,&IT33,MenWidth);
  647.     MIInit(&MI34,0,3*FontHeight,0x48,&IT34,MenWidth);
  648.  
  649.     ITInit(&IT31,"Increase by 8");
  650.     ITInit(&IT32,"Decrease by 8");
  651.     ITInit(&IT33,"Double");
  652.     ITInit(&IT34,"Halve");
  653.  
  654.     LeftPos = LeftPos + MenWidth;
  655.     DummyText.IText = (UBYTE *)"Changes___";
  656.     MenWidth = IntuiTextLength(&DummyText);
  657.  
  658.     MenuInit(&ChangeMenu,&PowerMenu,"Changes",LeftPos,MenWidth);
  659.     DummyText.IText = (UBYTE *)"Power down_________";
  660.     MenWidth = IntuiTextLength(&DummyText);
  661.  
  662.     ChangeMenu.FirstItem = &MI41;
  663.     MIInit(&MI41,&MI42,0,0x5a,&IT41,MenWidth);
  664.     MIInit(&MI42,&MI43,FontHeight,0x52,&IT42,MenWidth);
  665.     MIInit(&MI43,&MI44,2*FontHeight,0x3e,&IT43,MenWidth);
  666.     MIInit(&MI44,&MI45,3*FontHeight,0x3c,&IT44,MenWidth);
  667.     MIInit(&MI45,&MI46,4*FontHeight,0x55,&IT45,MenWidth);
  668.     MIInit(&MI46,&MI47,5*FontHeight,0x45,&IT46,MenWidth);
  669.     MIInit(&MI47,0,6*FontHeight,0x59,&IT47,MenWidth);
  670.  
  671.     ITInit(&IT41,"Zoom");
  672.     ITInit(&IT42,"Restore");
  673.     ITInit(&IT43,"Power Down");
  674.     ITInit(&IT44,"Power Up");
  675.     ITInit(&IT45,"Magnify");
  676.     ITInit(&IT46,"Reduce");
  677.     ITInit(&IT47,"Palette");
  678.  
  679.     LeftPos = LeftPos + MenWidth;
  680.     DummyText.IText = (UBYTE *)"Fractional Power_____";
  681.     MenWidth = IntuiTextLength(&DummyText);
  682.  
  683.     MenuInit(&PowerMenu,0,"Fractional Power",LeftPos,MenWidth);
  684.     DummyText.IText = (UBYTE *)"Multiply increment size by 10_________";
  685.     MenWidth = IntuiTextLength(&DummyText);
  686.  
  687.     PowerMenu.FirstItem = &MI21;
  688.     MIInit(&MI21,&MI22,0,0x2e,&IT21,MenWidth);
  689.     MIInit(&MI22,&MI23,FontHeight,0x30,&IT22,MenWidth);
  690.     MIInit(&MI23,&MI24,2*FontHeight,0x2f,&IT23,MenWidth);
  691.     MIInit(&MI24,&MI25,3*FontHeight,0x78,&IT24,MenWidth);
  692.     MIInit(&MI25,&MI26,4*FontHeight,0x5e,&IT25,MenWidth);
  693.     MIInit(&MI26,0,5*FontHeight,0x5c,&IT26,MenWidth);
  694.  
  695.     ITInit(&IT21,"Set Increment Size to 0.1");
  696.     ITInit(&IT22,"Set Increment Size to 0");
  697.     ITInit(&IT23,"Divide Increment Size by 10");
  698.     ITInit(&IT24,"Multiply Increment Size by 10");
  699.     ITInit(&IT25,"Increment Fraction by Size");
  700.     ITInit(&IT26,"Decrement Fraction by Size");
  701.  
  702.     SetMenuStrip(IntWindow,&ProjMenu);
  703.     MenVal = 0;;
  704. }
  705.  
  706. void ScreensClose()
  707. {
  708.     if(InfoWindow) {
  709.         CloseWindow(InfoWindow);
  710.         InfoWindow = 0;
  711.         }
  712.     if(IntWindow) ClearMenuStrip(IntWindow);
  713.     if(IntWindow) {
  714.         CloseWindow(IntWindow);
  715.         IntWindow = 0;
  716.         }
  717. }
  718.  
  719.  
  720. int OpenWrite(UBYTE *FilNam)
  721. {
  722.     FileHandle = Open(FilNam,MODE_NEWFILE);
  723.     if (!FileHandle)    return(-1);
  724.     return(0);
  725. }
  726.  
  727. int WriteFile(UBYTE *Source,ULONG FileLength)
  728. {
  729.     Write(FileHandle,(char *)Source,FileLength);
  730.     return(0);
  731. }
  732. void CloseWrite()
  733. {
  734.     Close(FileHandle);
  735. }
  736.  
  737. UBYTE *GetColors(MyColors,CTSize)
  738. UBYTE *MyColors;
  739. ULONG CTSize;
  740. {
  741. USHORT *CurrentColor,Red,Green,Blue,TCol;
  742.     CurrentColor = WBScreen->ViewPort.ColorMap->ColorTable;
  743.     while (CTSize)    {
  744.         Red = *CurrentColor;
  745.         Red = 0xf00 & Red;
  746.         Red >>= 4;
  747.         TCol = Red;
  748.         TCol >>= 4;
  749.         Red = Red | TCol;
  750.         *MyColors++ = (UBYTE)Red;
  751.         Green = *CurrentColor;
  752.         Green = 0xf0 & Green;
  753.         TCol = Green;
  754.         TCol >>= 4;
  755.         Green = Green | TCol;
  756.         *MyColors++ = (UBYTE)Green;
  757.         Blue = *CurrentColor++;
  758.         Blue = 0xf & Blue;
  759.         TCol = Blue;
  760.         Blue <<= 4;
  761.         Blue = Blue | TCol;
  762.         *MyColors++ = (UBYTE)Blue;
  763.         --CTSize;
  764.         }
  765.     return(MyColors);
  766. }
  767.  
  768. ULONG LongSwap(LngWrd)
  769. ULONG LngWrd;
  770. {
  771. ULONG LngBuf[1];
  772. UBYTE *ByteBuf;
  773. UBYTE Byte1,Byte2,Byte3,Byte4;
  774.     LngBuf[0] = LngWrd;
  775.     ByteBuf = (UBYTE *)LngBuf;
  776.     Byte1 = *ByteBuf++;
  777.     Byte2 = *ByteBuf++;
  778.     Byte3 = *ByteBuf++;
  779.     Byte4 = *ByteBuf;
  780.     ByteBuf = (UBYTE *)LngBuf;
  781.     *ByteBuf++ = Byte4;
  782.     *ByteBuf++ = Byte3;
  783.     *ByteBuf++ = Byte2;
  784.     *ByteBuf = Byte1;
  785.     LngWrd = LngBuf[0];
  786.     return(LngWrd);
  787. }
  788.  
  789. void StorePalette(PalPointer)
  790. UBYTE *PalPointer;
  791. {
  792. UBYTE *TabLoc;
  793. int TableCnt;
  794. UBYTE r,g,b,h,LNib,HNib;
  795.  
  796.     TableCnt = 0;
  797.     TabLoc = (UBYTE *)NewColorTable;
  798.     while (TableCnt < 0x100)    {
  799.         LNib = *TabLoc++;
  800.         HNib = LNib & 0xf0;
  801.         h = HNib;
  802.         h >>= 4;
  803.         h = h | HNib;
  804.         HNib = LNib & 0xf;
  805.         r = HNib;
  806.         r <<= 4;
  807.         r = r | HNib;
  808.         LNib = *TabLoc++;
  809.         HNib = LNib & 0xf0;
  810.         g = HNib;
  811.         g >>= 4;
  812.         g = g | HNib;
  813.         HNib = LNib & 0xf;
  814.         b = HNib;
  815.         b <<= 4;
  816.         b = b | HNib;
  817.         *PalPointer++ = b;
  818.         *PalPointer++ = g;
  819.         *PalPointer++ = r;
  820.         *PalPointer++ = h;
  821.         TableCnt++;
  822.         }
  823.  
  824. }
  825.  
  826. void ChangeNW(void)
  827. {
  828.     nw.Width = 180;
  829.     nw.Height = 40;
  830.     nw.LeftEdge = IntWindow->LeftEdge + 40;
  831.     nw.TopEdge = IntWindow->TopEdge + 40;
  832.     nw.Title = "           Saving";
  833.     nw.IDCMPFlags    =    CmpFlg;
  834.     nw.Flags        =    SMART_REFRESH|ACTIVATE;
  835.  }
  836.  
  837. void DisLine(LineRP,LinMes,LineNum)
  838. struct RastPort *LineRP;
  839. char *LinMes;
  840. int LineNum;
  841. {
  842.         SetAPen(LineRP,0);
  843.         RectFill(LineRP,15,20,130,35);
  844.         SetAPen(LineRP,1);
  845.         Move(LineRP,20,25);
  846.         sprintf(&MyStringBuf[0],LinMes);
  847.         sprintf(&MyStringBuf[strlen(MyStringBuf)],"%d.",(int)(WHeight-LineNum));
  848.         Text(LineRP,&MyStringBuf[0],strlen(MyStringBuf)-1);
  849. }
  850.  
  851. void SaveBMP(void)
  852. {
  853. UBYTE *BMPHdrBuffer;
  854.  
  855. UBYTE *LineBuff;
  856. UBYTE *BMPBodyBuffer;
  857. ULONG *BMPLPointer;
  858. UWORD *BMPWPointer;
  859. struct Window *SavingWnd;
  860. ULONG BMPBodyLength,BPPix;
  861. UWORD WAHL,WAHH;
  862. BPTR BMHandle;
  863. LONG PixCount;
  864.  
  865. UWORD LBufLength,LinePos,DstMode;
  866. int LineNum,HdrSize,WDepth;
  867. char *FilNam;
  868. UBYTE r,g,b;
  869.  
  870.     WDepth = IntWindow->RPort->BitMap->Depth;
  871.     if (BPP == 1) {
  872.         HdrSize = 0x436;
  873.         FilNam = "Mand8.bmp";
  874.         WAHL = WWidth;
  875.         BPPix = 0x00080001;
  876.         if (WDepth == 4) FilNam = "Mand4.bmp";
  877.         if (WDepth == 5) FilNam = "Mand5.bmp";
  878.         }
  879.     else {
  880.         HdrSize = 0x36;
  881.         FilNam = "Mand.bmp";
  882.         WAHL = 3*WWidth;
  883.         BPPix = 0x00180001;
  884.         }
  885.     BMPHdrBuffer = AllocMem(HdrSize,MemMode);
  886.     BMPWPointer = (UWORD *)BMPHdrBuffer;
  887.     *BMPWPointer++ = 0x424d;    /* 'BM' */
  888.     BMPLPointer = (ULONG *)BMPWPointer;
  889.     WAHH = WAHL;
  890.     WAHL >>= 2;  /* Divide by 4 */
  891.     WAHL <<= 2;  /* Multiply by 4 */
  892.     while (WAHH - WAHL) {
  893.         WAHH++;
  894.         WAHL = WAHH;
  895.         WAHL >>= 2;
  896.         WAHL <<= 2;
  897.         }
  898.     WAHL = WAHH;
  899.     LBufLength = WAHH;
  900.     LineBuff = AllocMem(LBufLength+4,MemMode);
  901.     BMPBodyLength = WAHH*WHeight;
  902.     *BMPLPointer++ = LongSwap(BMPBodyLength + HdrSize);
  903.     *BMPLPointer++ = 0;
  904.     *BMPLPointer++ = LongSwap(HdrSize);    /* 0x36 or 0x436 bytes of header.*/
  905.     *BMPLPointer++ = LongSwap(0x28);    /* 0x28 = 40 bytes remaining before palette (if any).*/
  906.     *BMPLPointer++ = LongSwap((ULONG)WWidth);
  907.     *BMPLPointer++ = LongSwap((ULONG)WHeight);
  908.     *BMPLPointer++ = LongSwap(BPPix);
  909.     *BMPLPointer++ = 0;
  910.     *BMPLPointer++ = LongSwap(BMPBodyLength);
  911.     *BMPLPointer++ = 0;
  912.     *BMPLPointer++ = 0;
  913.     *BMPLPointer++ = 0;
  914.     *BMPLPointer++ = 0;
  915.     if (BPP == 1) StorePalette((UBYTE *)BMPLPointer);
  916.     LineNum = WHeight - 1;
  917. /*
  918.     nw.Width = 180;
  919.     nw.Height = 40;
  920.     nw.LeftEdge = IntWindow->LeftEdge + 40;
  921.     nw.TopEdge = IntWindow->TopEdge + 40;
  922.     nw.Title = "           Saving";
  923.     nw.IDCMPFlags    =    CmpFlg;
  924.     nw.Flags        =    SMART_REFRESH|ACTIVATE;*/
  925.     ChangeNW();
  926.     SavingWnd = OpenWindow(&nw);
  927.     BMHandle = Open(FilNam,MODE_NEWFILE);
  928.     Write(BMHandle,BMPHdrBuffer,HdrSize);
  929.     DstMode = (UWORD)(3*WWidth);
  930.     SetFont(SavingWnd->RPort,CWFont);
  931.     while (LineNum >= 0)    {
  932.         BMPBodyBuffer = LineBuff + LBufLength - 1;
  933.         *BMPBodyBuffer-- = 0;
  934.         *BMPBodyBuffer-- = 0;
  935.         *BMPBodyBuffer-- = 0;
  936.         *BMPBodyBuffer = 0;
  937.         LinePos = (UWORD)IntWindow->BorderTop + (UWORD)LineNum;
  938.         if (BPP == 1)    {
  939.             ReadPixelLine8(IntWindow->RPort,IntWindow->BorderLeft,LinePos,WWidth,LineBuff,&MainWRast);
  940.             }
  941.         else    {
  942.             PixCount = ReadPixelArray((APTR*)LineBuff,0,0,DstMode,IntWindow->RPort,IntWindow->BorderLeft,LinePos,(UWORD)WWidth,1,RECTFMT_RGB);
  943.             PixCount = WWidth;
  944.             BMPBodyBuffer = LineBuff;
  945.             while (PixCount)    {
  946.                 r = *BMPBodyBuffer++;
  947.                 g = *BMPBodyBuffer++;
  948.                 b = *BMPBodyBuffer;
  949.                 --BMPBodyBuffer;
  950.                 --BMPBodyBuffer;
  951.                 *BMPBodyBuffer++ = b;
  952.                 *BMPBodyBuffer++ = g;
  953.                 *BMPBodyBuffer++ = r;
  954.                 --PixCount;
  955.                 }
  956.             }
  957.         Write(BMHandle,LineBuff,LBufLength);
  958.         DisLine(SavingWnd->RPort,"Line ",LineNum);
  959.         --LineNum;
  960.         }
  961.     Close(BMHandle);
  962.     if (SavingWnd) CloseWindow(SavingWnd);
  963.     if (LineBuff) FreeMem(LineBuff,LBufLength+4);
  964.     if (BMPHdrBuffer) FreeMem(BMPHdrBuffer,HdrSize);
  965. }
  966.  
  967. void SaveP(void)
  968. {
  969. DOUBLE *DblPtr;
  970. ULONG    *LngPtr;
  971.  
  972. UBYTE *DataBuf;
  973.     DataBuf = AllocMem(48,MEMF_CLEAR);
  974.     DblPtr = (DOUBLE *)DataBuf;
  975.     *DblPtr++ = XCenter;
  976.     *DblPtr++ = YCenter;
  977.     *DblPtr++ = HWidth;
  978.     *DblPtr++ = HHeight;
  979.     *DblPtr++ = Factor;
  980.     LngPtr = (LONG *)DblPtr;
  981.     *LngPtr++ = MaxCnt;
  982.     *LngPtr++ = Power;
  983.     OpenWrite((UBYTE *)"Mand.prm");
  984.     WriteFile(DataBuf,48);
  985.     CloseWrite();
  986.     if (DataBuf) FreeMem(DataBuf,48);
  987. }
  988.  
  989. void LoadP(void)
  990. {
  991. DOUBLE *DblPtr;
  992. ULONG    *LngPtr;
  993.  
  994. UBYTE *DataBuf;
  995.     DataBuf = AllocMem(48,MEMF_CLEAR);
  996.     FileHandle = Open((UBYTE *)"Mand.prm",MODE_OLDFILE);
  997.     if (!FileHandle)    {
  998.         printf("The file Mand.prm can't be found!\n");
  999.         return;
  1000.         }
  1001.     Read(FileHandle,DataBuf,48);
  1002.     Close(FileHandle);
  1003.     LastX = XCenter;
  1004.     LastY = YCenter;
  1005.     LastFactor = Factor;
  1006.     DblPtr = (DOUBLE *)DataBuf;
  1007.     XCenter = *DblPtr++;
  1008.     YCenter =*DblPtr++;
  1009.     HWidth = *DblPtr++;
  1010.     HHeight = *DblPtr++;
  1011.     Factor = *DblPtr++;
  1012.     DX = 1./Factor;
  1013.     LngPtr = (LONG *)DblPtr;
  1014.     MaxCnt = *LngPtr++;
  1015.     Power = *LngPtr++;
  1016.     if (DataBuf) FreeMem(DataBuf,48);
  1017.     WriteStuff();
  1018. }
  1019.  
  1020.  
  1021.  
  1022. UBYTE PaletteNumberFind( UBYTE Color)
  1023. {
  1024. UBYTE NColor;
  1025.     NColor = Color + 4;
  1026.     if (NColor > 16) NColor = NColor + 3;
  1027.     return(NColor);
  1028. }
  1029.  
  1030. void SmallPalette(void)
  1031. {
  1032. UWORD ColTab[] = {0,0x8,0xc,0xf,0x4c,0xc4,0xf0,0x4f0,0x880,0xc40,0xf00,0xf04,0xf08,0xf0c,0xf0f,0xa0a};
  1033.     LoadRGB4(&WBScreen->ViewPort,&ColTab[0],16);
  1034. }
  1035.  
  1036. void SetPalette(void)
  1037. {
  1038. UWORD *Src,*Dst;
  1039. DOUBLE    RShade;
  1040. int Mult1,Mult2,ColMax,BotCol;
  1041. ULONG CntCol;
  1042. ULONG NColor;
  1043. UBYTE    Shade,Shade2;
  1044. /*UBYTE    Color,NColor,Shade,Shade2;*/
  1045.     if (WBScreen->RastPort.BitMap->Depth == 4)    NumColors = 16;
  1046.     if (WBScreen->RastPort.BitMap->Depth == 5)    NumColors = 32;
  1047.     if (WBScreen->RastPort.BitMap->Depth == 6)    NumColors = 64;
  1048.     if (WBScreen->RastPort.BitMap->Depth == 7)    NumColors = 128;
  1049.     if (WBScreen->RastPort.BitMap->Depth == 8)    NumColors = 256;
  1050.     TopCol = NumColors - 1;
  1051.     if (WBScreen->RastPort.BitMap->Depth < 5) {
  1052. /*        SmallPalette(); */
  1053.         return;
  1054.         }
  1055. /*    if (SDepth == 15) NumColors = 0x8000;*/
  1056.     if (SDepth >= 15) NumColors = 0x10000;
  1057.     if (NumColors <= 256) TableSize = 4000;
  1058.     else TableSize = 0x40000;
  1059.     OldColorTable = WBScreen->ViewPort.ColorMap->ColorTable;
  1060.     TopCol = NumColors - 1;
  1061.     NewColorTable = AllocMem(TableSize,MemMode);
  1062.     ColorTable32 = (UBYTE *)NewColorTable;
  1063.     if (!NewColorTable) {
  1064.         printf("Failed in allocation!\n");
  1065.         return;
  1066.         }
  1067.     CntCol = 0;
  1068.     Dst = (UWORD *)NewColorTable;
  1069.     Src = (UWORD *)OldColorTable;
  1070.     while (CntCol < NumColors)    {
  1071.         *Dst++ = *Src++;
  1072.         CntCol++;
  1073.         }
  1074.     ScreenToFront(WBScreen);
  1075.     if (NumColors > 256)    {
  1076.         Palette32();
  1077.         return;
  1078.         }
  1079.     WBScreen->ViewPort.ColorMap->ColorTable = NewColorTable;
  1080.     Mult1 = 4*256/NumColors;
  1081.     Mult2 = 3*Mult1/2;
  1082.     ColMax = NumColors/8;
  1083.     Mult2 = 6;
  1084.     Color = 0;
  1085.     BotCol = 4;
  1086.     SetRGB32(&(WBScreen->ViewPort),0,0xaa*BFactor,0xaa*BFactor,0xaa*BFactor);
  1087.     SetRGB32(&(WBScreen->ViewPort),1,0,0,0);
  1088.     SetRGB32(&(WBScreen->ViewPort),2,0xff*BFactor,0xff*BFactor,0xff*BFactor);
  1089.     SetRGB32(&(WBScreen->ViewPort),3,0x64*BFactor,0x88*BFactor,0xb8*BFactor);
  1090.     Color = 4;
  1091.     while (Color < ColMax)    {
  1092.         Shade = Mult1*Color + 128;
  1093.         Shade2 = Mult2*Color;
  1094.         NColor = PaletteNumberFind(Color);
  1095.         SetRGB32(&(WBScreen->ViewPort),NColor,0,BFactor*Shade2,BFactor*Shade);
  1096.         Color++;
  1097.         }
  1098.     while (Color < 2*ColMax)    {
  1099.         Shade = Color - ColMax;
  1100.         Shade2 = Mult2*Shade;
  1101.         Shade = Mult1*Shade + 128;
  1102.         NColor = PaletteNumberFind(Color);
  1103.         SetRGB32(&(WBScreen->ViewPort),NColor,BFactor*Shade,0,BFactor*Shade2);
  1104.         Color++;
  1105.         }
  1106.     while (Color < 3*ColMax)    {
  1107.         Shade = Color - 2*ColMax;
  1108.         Shade = Mult1*Shade + 128;
  1109.         RShade = 2.*Shade/3.;
  1110.         Shade2 = RShade;
  1111.         NColor = PaletteNumberFind(Color);
  1112.         SetRGB32(&(WBScreen->ViewPort),NColor,BFactor*Shade,BFactor*Shade2,0);
  1113.         Color++;
  1114.         }
  1115.     while (Color < 4*ColMax)    {
  1116.         Shade = Color - 3*ColMax;
  1117.         Shade2 = Mult2*Shade;
  1118.         Shade = Mult1*Shade + 128;
  1119.         NColor = PaletteNumberFind(Color);
  1120.         SetRGB32(&(WBScreen->ViewPort),NColor,BFactor*Shade,BFactor*Shade,BFactor*Shade2);
  1121.         Color++;
  1122.         }
  1123.     while (Color < 5*ColMax)    {
  1124.         Shade = Color - 4*ColMax;
  1125.         Shade = Mult1*Shade + 128;
  1126.         NColor = PaletteNumberFind(Color);
  1127.         if (NColor < TopCol)    SetRGB32(&(WBScreen->ViewPort),NColor,BFactor*Shade2,BFactor*Shade,0);
  1128.         Color++;
  1129.         }
  1130.     while (Color < 6*ColMax)    {
  1131.         Shade = Color - 5*ColMax;
  1132.         Shade2 = Mult2*Shade;
  1133.         Shade = Mult1*Shade + 128;
  1134.         NColor = PaletteNumberFind(Color);
  1135.         if (NColor < TopCol)    SetRGB32(&(WBScreen->ViewPort),NColor,0,BFactor*Shade,BFactor*Shade);
  1136.         Color++;
  1137.         }
  1138.     while (Color < 7*ColMax)    {
  1139.         Shade = Color - 6*ColMax;
  1140.         Shade = Mult1*Shade + 128;
  1141.         NColor = PaletteNumberFind(Color);
  1142.         if (NColor < TopCol)    SetRGB32(&(WBScreen->ViewPort),NColor,BFactor*Shade,0,BFactor*Shade);
  1143.         Color++;
  1144.         }
  1145.     while (Color < TopCol - 6)    {
  1146.         Shade = Color - 7*ColMax;
  1147.         Shade = Mult1*Shade + 96;
  1148.         Shade2 = Shade + 59;
  1149.         NColor = PaletteNumberFind(Color);
  1150.         if (NColor < TopCol)    SetRGB32(&(WBScreen->ViewPort),NColor,BFactor*Shade2,BFactor*Shade,BFactor*Shade2);
  1151.         Color++;
  1152.         }
  1153.     SetRGB32(&(WBScreen->ViewPort),TopCol,120*BFactor,0,120*BFactor);
  1154. }
  1155.  
  1156.  
  1157. void Palette32(void)
  1158. {
  1159. LONG C32Cnt;
  1160. UBYTE *Begin,*Dst;
  1161. UBYTE Red,Green,Blue;
  1162. BYTE dRed,dGreen,dBlue;
  1163.     Dst = (UBYTE *)NewColorTable;
  1164.     Begin = Dst;
  1165.     C32Cnt = 0;
  1166.     Red = 1;
  1167.     Green = 2;
  1168.     Blue = 128;
  1169.     dRed = 1;
  1170.     dGreen = 2;
  1171.     dBlue = 4;
  1172.     while (C32Cnt < 0xfffe)    {
  1173.         *Dst++ = 0;
  1174.         if (PalOpt == 0)    {
  1175.             *Dst++ = Red;
  1176.             *Dst++ = Green;
  1177.             *Dst++ = Blue;
  1178.             }
  1179.         if (PalOpt == 1)    {
  1180.             *Dst++ = Green;
  1181.             *Dst++ = Blue;
  1182.             *Dst++ = Red;
  1183.             }
  1184.         if (PalOpt == 2)    {
  1185.             *Dst++ = Blue;
  1186.             *Dst++ = Red;
  1187.             *Dst++ = Green;
  1188.             }
  1189.         if (PalOpt == 3)    {
  1190.             *Dst++ = Blue;
  1191.             *Dst++ = Green;
  1192.             *Dst++ = Red;
  1193.             }
  1194.         if (PalOpt == 4)    {
  1195.             *Dst++ = Green;
  1196.             *Dst++ = Red;
  1197.             *Dst++ = Blue;
  1198.             }
  1199.         if (PalOpt == 5)    {
  1200.             *Dst++ = Red;
  1201.             *Dst++ = Blue;
  1202.             *Dst++ = Green;
  1203.             }
  1204.         C32Cnt++;
  1205.         Blue = Blue + dBlue;
  1206.         Green = Green + dGreen;
  1207.         Red = Red + dRed;
  1208.         if ((Blue > 0xfb)||(Blue < 4))    dBlue = - dBlue;
  1209.         if ((Green >= 0xfd)||(Green < 2))    dGreen = - dGreen;
  1210.         if ((Red >= 0xfe)||(Red < 1))    dRed = - dRed;
  1211.         }
  1212.     *Dst++ = 0;
  1213.     *Dst++ = 0xff;
  1214.     *Dst++ = 0xff;
  1215.     *Dst++ = 0xff;
  1216.     *Dst++ = 0;
  1217.  
  1218.     if ((PalOpt == 0)||(PalOpt == 3))    {
  1219.         *Dst++ = 120;
  1220.         *Dst++ = 0;
  1221.         *Dst++ = 120;
  1222.         }
  1223.     if ((PalOpt == 1)||(PalOpt == 5))    {
  1224.         *Dst++ = 120;
  1225.         *Dst++ = 120;
  1226.         *Dst++ = 0;
  1227.         }
  1228.     if ((PalOpt == 2)||(PalOpt == 4))    {
  1229.         *Dst++ = 0;
  1230.         *Dst++ = 120;
  1231.         *Dst++ = 120;
  1232.         }
  1233.  
  1234.     Dst = Begin;
  1235.     WBScreen->ViewPort.ColorMap->ColorTable = NewColorTable;
  1236. }
  1237.  
  1238. void WindowSet()
  1239. {
  1240.  
  1241. nw.LeftEdge        =    0;
  1242. nw.TopEdge        =    0;            /* Expose screen drag bar */
  1243. nw.Width        =    64;
  1244. nw.Height        =    30;
  1245. nw.DetailPen    =    5;
  1246. nw.BlockPen        =    2;
  1247. nw.IDCMPFlags    =    CLOSEWINDOW ;
  1248. nw.Type            =    WBENCHSCREEN;
  1249. nw.Type            =    PUBLICSCREEN;
  1250. nw.Flags        =    WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|SMART_REFRESH|ACTIVATE|REPORTMOUSE;
  1251. /*nw.Flags        =    WINDOWDRAG|WINDOWDEPTH|SMART_REFRESH|ACTIVATE|REPORTMOUSE | WFLG_NEWLOOKMENUS | WFLG_SIZEGADGET;*/
  1252. nw.FirstGadget    =    NULL;
  1253. nw.CheckMark    =    NULL;
  1254. nw.Screen        =    0;
  1255. WindowName     = &Title[0];
  1256. nw.Title        =    (UBYTE *)WindowName;
  1257. nw.BitMap        =    NULL;
  1258. nw.MinWidth        =    100;
  1259. nw.MinHeight    =    75;
  1260. nw.MaxWidth        =    SWidth+20;
  1261. nw.MaxHeight    =    SHeight+20;
  1262.     Delay(10);
  1263.     InfoWindow = (struct Window *)OpenWindow( &nw );
  1264.     WBScreen = InfoWindow -> WScreen;
  1265.     DefFont = WBScreen->Font;
  1266.     WBRast = InfoWindow -> RPort;
  1267.     MyPort    = InfoWindow -> UserPort;
  1268.     WBScreen = InfoWindow->WScreen;
  1269.     WDepth = WBScreen->RastPort.BitMap->Depth;
  1270.     FontHeight = 1.2*(DefFont->ta_YSize);
  1271.     TFHeight = GfxBase->DefaultFont->tf_YSize;
  1272.     IWHeight = 21*TFHeight;
  1273.     InfBTop = InfoWindow->BorderTop;
  1274.     InfBLeft = InfoWindow->BorderLeft;
  1275.     IWWidth = TextLength(WBRast,&Mesag7[0],strlen(Mesag7));
  1276.     TwoSpace = TextLength(WBRast,(STRPTR)"  ",2);
  1277.     IWWidth = IWWidth + 2*TwoSpace;
  1278.     if (IWHeight + InfBTop < WBScreen->Height)    ChangeWindowBox(InfoWindow,0,0,IWWidth+InfBLeft+InfoWindow->BorderRight,IWHeight+InfBTop);
  1279.     else ChangeWindowBox(InfoWindow,0,0,IWWidth+InfBLeft+InfoWindow->BorderRight,WBScreen->Height);
  1280.     SetWindowTitles(InfoWindow,(UBYTE *)" Information about this Fractal",(UBYTE *)-1);
  1281.     DFont = GfxBase->DefaultFont;
  1282.     if (!CWFont) CWFont = OpenFont(&topaz8);
  1283.     DefBold.ta_Name = DFont->tf_Message.mn_Node.ln_Name;
  1284.     DefBold.ta_YSize = 14*DFont->tf_YSize/10;
  1285.     DefBold.ta_Style = 2;
  1286.     if (DiskfontBase) BFont = OpenDiskFont(&DefBold);
  1287.     nw.BlockPen = 3;
  1288.  
  1289.     nw.Screen = WBScreen;
  1290.     IsCyberScreen = FALSE;
  1291.     ThisMode = WBScreen->ViewPort.ColorMap->VPModeID;
  1292.     BPP = 1;
  1293.     if (CyberGfxBase)    {
  1294.         if (IsCyberModeID(ThisMode))    {
  1295.             IsCyberScreen = TRUE;
  1296.             InitVS();
  1297.             }
  1298.         }
  1299.     SetPalette();
  1300. }
  1301.  
  1302. WORD LengthDescript()
  1303. {
  1304. WORD chPos;
  1305.     if (SysFlag == 0)    chPos = GetLength((STRPTR)" 68000");
  1306.     else    {
  1307. /*        printf("SysFlag = %x\n",SysFlag);*/
  1308.         if (SysFlag & 0x10) chPos = GetLength((STRPTR)" 68060");
  1309.         else if (SysFlag & 0x8) chPos = GetLength((STRPTR)" 68040");
  1310.         else if (SysFlag & 0x4) chPos = GetLength((STRPTR)" 68030");
  1311.         else if (SysFlag & 0x2) chPos = GetLength((STRPTR)" 68020");
  1312.         chPos = chPos + GetLength((STRPTR)"'");
  1313.         if (SysFlag & AFF_68882) chPos = chPos + GetLength((STRPTR)St882);
  1314. /*        if (SysFlag & AFF_68882) chPos = chPos + GetLength((STRPTR)" 68882");*/
  1315.         else if (SysFlag & AFF_68881) chPos = chPos + GetLength((STRPTR)" 68881");
  1316.         }
  1317.     return(chPos);
  1318. }
  1319.  
  1320. void CheckCOPP()
  1321. {
  1322.     if (SysFlag & AFF_68882)    {
  1323.         Text(WBRast,(STRPTR)Comma,1);
  1324.         Text(WBRast,(STRPTR)&St882[0],strlen(St882));
  1325.         }
  1326.     else if (SysFlag & AFF_68881)    {
  1327.         Text(WBRast,(STRPTR)Comma,1);
  1328.         Text(WBRast,(STRPTR)" 68881",6);
  1329.         }
  1330. }
  1331.  
  1332. void DescribeSystem()
  1333. {
  1334. /*    if (!SysFlag)    {
  1335.         Text(WBRast,(STRPTR)" 68000",6);
  1336.         return;
  1337.         }
  1338.     if (SysFlag & AFF_68060) {
  1339.         Text(WBRast,(STRPTR)" 68060",6);
  1340.         if (SysFlag & AFF_FPU40)    {
  1341.             CheckCOPP();
  1342.             return;
  1343.             }
  1344.         }
  1345.     if (SysFlag & AFF_68040) {
  1346.         Text(WBRast,(STRPTR)" 68040",6);
  1347.         CheckCOPP();
  1348.         return;
  1349.         }
  1350.     if (SysFlag & AFF_68030) {
  1351.         Text(WBRast,(STRPTR)" 68030",6);
  1352.         CheckCOPP();
  1353.         return;
  1354.         }
  1355.     if (SysFlag & AFF_68020)    {
  1356.         Text(WBRast,(STRPTR)" 68020",6);
  1357.         CheckCOPP();
  1358.         return;
  1359.         }
  1360.     if (SysFlag & AFF_68010)    {
  1361.         Text(WBRast,(STRPTR)" 68010",6);
  1362.         CheckCOPP();
  1363.         return;
  1364.         }
  1365. */
  1366.     Text(WBRast,&CPUStrBuf[0],strlen(CPUStrBuf));
  1367. }
  1368.  
  1369. WORD GetLength(TempMsg)
  1370. UBYTE *TempMsg;
  1371. {
  1372. WORD chPos;
  1373.     chPos = TextLength(WBRast,TempMsg,strlen(TempMsg));
  1374.     return(chPos);
  1375. }
  1376. WORD GethPos(TempMsg)
  1377. UBYTE *TempMsg;
  1378. {
  1379. WORD    chPos;
  1380.     chPos = TextLength(WBRast,TempMsg,strlen(TempMsg));
  1381.     chPos = IWWidth - chPos;
  1382.     chPos >>= 1;
  1383.     chPos = chPos + InfBLeft;
  1384.     return(chPos);
  1385. }
  1386.  
  1387.  
  1388. void DisCnt(void)
  1389. {
  1390. static char    SrtBuf[30];
  1391.     Move(WBRast,160,19*TFHeight);
  1392.     SetAPen(WBRast,2);
  1393.     sprintf(&SrtBuf[0],(STRPTR)"Working on line %d.        ",ytemp);
  1394.     Text(WBRast,(STRPTR)SrtBuf,strlen(SrtBuf));
  1395. }
  1396.  
  1397. void WriteStuff()
  1398. {
  1399. static    char    Mesage[]     = "SManWOS Beta 2.0 (3/28/2001)";
  1400. static    char    Mesag1[]     = "by David M. McKinstry";
  1401. static    char    Mesag2[]    = "Copyright ";
  1402. static    char    Mesag2c[]    = " 1998-2001";
  1403. char    StrngBuffer[200];
  1404. UBYTE    Mesag2b[]    = {0xa9};
  1405. ULONG    MemSize;
  1406. char *TmpPtr;
  1407. WORD vPos,hPos,chPos,SpcPlus;
  1408.     SpcPlus = 3*TFHeight/2;
  1409.     --SpcPlus;
  1410.     vPos = InfBTop + TFHeight;
  1411.     SetAPen(WBRast,1);
  1412.     chPos = GethPos(&Mesage[0]);
  1413.     Move(WBRast,chPos,vPos);
  1414.     Text(WBRast,(STRPTR)Mesage,strlen(Mesage));
  1415.     vPos = vPos + TFHeight;
  1416.     Mesag1[5] = 0x76;
  1417.     chPos = GethPos(&Mesag1[0]);
  1418.     Move(WBRast,chPos,vPos);
  1419.     Text(WBRast,(STRPTR)Mesag1,strlen(Mesag1));
  1420.     hPos = IWWidth/8;
  1421.     vPos = vPos + TFHeight;
  1422.     SetAPen(WBRast,3);
  1423.     chPos = TextLength(WBRast,&Mesag2[0],strlen(Mesag2));
  1424.     chPos = chPos + TextLength(WBRast,&Mesag2b[0],1);
  1425.     chPos = chPos + TextLength(WBRast,&Mesag2c[0],strlen(Mesag2c));
  1426.     chPos = IWWidth - chPos;
  1427.     chPos >>= 1;
  1428.     Move(WBRast,chPos,vPos);
  1429.     Text(WBRast,(STRPTR)Mesag2,strlen(Mesag2));
  1430.     Text(WBRast,(STRPTR)Mesag2b,1);
  1431.     Text(WBRast,(STRPTR)Mesag2c,strlen(Mesag2c));
  1432.     vPos = vPos + SpcPlus;
  1433.     SetAPen(WBRast,1);
  1434.     chPos = LengthDescript();
  1435.     chPos = chPos + GetLength(&Mesag3[0]);
  1436.     chPos = IWWidth - chPos;
  1437.     chPos >>= 1;
  1438.     Move(WBRast,40,vPos);
  1439.  
  1440.     Text(WBRast,(STRPTR)Mesag3,strlen(Mesag3));
  1441.     DescribeSystem();
  1442.  
  1443.     vPos = vPos + TFHeight;
  1444.     Move(WBRast,hPos,vPos);
  1445.     MemSize = AvailMem(MEMF_CHIP);
  1446.     TmpPtr = &ChpEnd[0];
  1447.     --TmpPtr;
  1448.     sprintf(TmpPtr,"%d",(int)MemSize);
  1449.     Text(WBRast,(STRPTR)ChpMsg,strlen(ChpMsg));
  1450.     Move(WBRast,61*IWWidth/100,vPos);
  1451.     MemSize = AvailMem(MEMF_FAST);
  1452.     TmpPtr = &FstEnd[0];
  1453.     --TmpPtr;
  1454.     sprintf(TmpPtr,"%d",(int)MemSize);
  1455.     Text(WBRast,(STRPTR)FstMsg,strlen(FstMsg));
  1456.  
  1457.     SetAPen(WBRast,2);
  1458.     vPos = vPos + SpcPlus;
  1459.     chPos = GethPos(Mesag4);
  1460.     Move(WBRast,chPos,vPos);
  1461.     Text(WBRast,(STRPTR)Mesag4,strlen(Mesag4));
  1462.  
  1463.     SetAPen(WBRast,1);
  1464.     vPos = vPos + SpcPlus;
  1465.     Move(WBRast,hPos,vPos);
  1466.     TmpPtr = &WdtEnd[0];
  1467.     sprintf(TmpPtr,"%d",WWidth);
  1468.     Text(WBRast,(STRPTR)WdtMsg,strlen(WdtMsg));
  1469.     Text(WBRast,(STRPTR)"        ",8);
  1470.     Move(WBRast,hPos + TextLength(WBRast,&WdtMsg[0],strlen(WdtMsg)),vPos);
  1471.     Text(WBRast,(STRPTR)TmpPtr,strlen(TmpPtr));
  1472.     Move(WBRast,61*IWWidth/100,vPos);
  1473.     TmpPtr = &HgtEnd[0];
  1474.     sprintf(TmpPtr,"%d",WHeight);
  1475.     Text(WBRast,(STRPTR)HgtMsg,strlen(HgtMsg));
  1476.     Text(WBRast,(STRPTR)"        ",8);
  1477.     Move(WBRast,61*IWWidth/100 + TextLength(WBRast,&HgtMsg[0],strlen(HgtMsg)),vPos);
  1478.     Text(WBRast,(STRPTR)TmpPtr,strlen(TmpPtr));
  1479.     vPos = vPos + SpcPlus;
  1480.     SetAPen(WBRast,1);
  1481.     TmpPtr = &MagMsg[16];
  1482.     sprintf(TmpPtr,"%e",Factor);
  1483.     Move(WBRast,hPos,vPos);
  1484.     Text(WBRast,(STRPTR)MagMsg,strlen(MagMsg));
  1485.  
  1486.     SetAPen(WBRast,1);
  1487.     TmpPtr = &CntEnd[0];
  1488.     sprintf(TmpPtr,(STRPTR)"%d",MaxCnt);
  1489.     Move(WBRast,61*IWWidth/100,vPos);
  1490.     Text(WBRast,(STRPTR)CntMsg,strlen(CntMsg));
  1491.     Text(WBRast,(STRPTR)"        ",8);
  1492.     Move(WBRast,61*IWWidth/100 + TextLength(WBRast,&CntMsg[0],strlen(CntMsg)),vPos);
  1493.     Text(WBRast,(STRPTR)TmpPtr,strlen(TmpPtr));
  1494.  
  1495.     vPos = vPos + SpcPlus;
  1496.     SetAPen(WBRast,3);
  1497.     chPos = GethPos(&ScrMsg[0]);
  1498.     Move(WBRast,chPos,vPos);
  1499.     Text(WBRast,(STRPTR)ScrMsg,strlen(ScrMsg));
  1500.  
  1501.     SetAPen(WBRast,1);
  1502.     vPos = vPos + TFHeight;
  1503.     Move(WBRast,hPos,vPos);
  1504.     TmpPtr = &XPsEnd[0];
  1505.     sprintf(TmpPtr,"%#.14e",(HWidth-XCenter)/Factor);
  1506.     Text(WBRast,(STRPTR)XPos,strlen(XPos));
  1507.     Text(WBRast,(STRPTR)"                          ",24);
  1508.     Move(WBRast,hPos+TextLength(WBRast,&XPos[0],strlen(XPos)),vPos);
  1509.     Text(WBRast,(STRPTR)TmpPtr,strlen(TmpPtr));
  1510.  
  1511.     Move(WBRast,61*IWWidth/100,vPos);
  1512.     TmpPtr = &YPsEnd[0];
  1513.     sprintf(TmpPtr,"%#.14e",(HHeight-YCenter)/Factor);
  1514.     Text(WBRast,(STRPTR)YPos,strlen(YPos));
  1515.     Text(WBRast,(STRPTR)"                          ",24);
  1516.     Move(WBRast,61*IWWidth/100+TextLength(WBRast,&YPos[0],strlen(YPos)),vPos);
  1517.     Text(WBRast,(STRPTR)TmpPtr,strlen(TmpPtr));
  1518.  
  1519.     SetAPen(WBRast,3);
  1520.     vPos = vPos + SpcPlus;
  1521.     if (PowerF == 0.) {
  1522.         if (Power < 10) chPos = GethPos(&MandMsg[0]);
  1523.         else    chPos = GethPos(&MandMsgG[0]);
  1524.         }
  1525.     else chPos = GethPos(&MandMsgP[0]);
  1526.     Move(WBRast,chPos,vPos);
  1527.     if (PowerF == 0.)    {
  1528.         if (Power < 10) Text(WBRast,(STRPTR)MandMsg,strlen(MandMsg));
  1529.         else    Text(WBRast,(STRPTR)MandMsgG,strlen(MandMsgG));
  1530.         }
  1531.     else {
  1532.         Text(WBRast,(STRPTR)MandMsgP,strlen(MandMsgP));
  1533.         MandMsgP[strlen(MandMsgP)-3] = 0x2d;
  1534.         SetDrMd(WBRast,JAM1);
  1535.         Move(WBRast,chPos,vPos);
  1536.         Text(WBRast,(STRPTR)MandMsgP,strlen(MandMsgP)-2);
  1537.         SetDrMd(WBRast,JAM2);
  1538.         MandMsgP[strlen(MandMsgP)-3] = 0x30;
  1539.         }
  1540.     vPos = vPos - TFHeight/3;
  1541.     if (PowerF == 0.) chPos = chPos + TextLength(WBRast,&MandMsg[0],18);
  1542.     else chPos = chPos + TextLength(WBRast,&MandMsgP[0],18);
  1543.     Move(WBRast,chPos,vPos);
  1544.     vPos = vPos + TFHeight/3;
  1545.  
  1546.     TmpPtr = &StrngBuffer[0];
  1547.     if (PowerF == 0.) {
  1548.         sprintf(TmpPtr,"%d",Power);
  1549.         if (Power < 10) Text(WBRast,(STRPTR)TmpPtr,1);
  1550.         else Text(WBRast,(STRPTR)TmpPtr,2);
  1551.         }
  1552.     else {
  1553. /*        sprintf(TmpPtr,"%d",Power);
  1554.         TmpPtr++;
  1555.         if (Power > 9) TmpPtr++;*/
  1556.         sprintf(TmpPtr,"%#2.16f",PowerN);
  1557. /*        --TmpPtr;
  1558.         if (Power > 9) TmpPtr--;*/
  1559.         Text(WBRast,(STRPTR)TmpPtr,16);
  1560.         }
  1561.     if (((SysFlag & AFF_68881)||(SysFlag & AFF_68882))&&((SysFlag & AFF_68020)||(SysFlag & AFF_68030)))    CPU = 1;
  1562.  
  1563.     SetAPen(WBRast,2);
  1564.  
  1565.     vPos = vPos + SpcPlus;
  1566.     chPos = GethPos(&Mesag5[0]);
  1567. /*    Move(WBRast,chPos,vPos);
  1568.     Text(WBRast,(STRPTR)Mesag5,strlen(Mesag5));
  1569.     vPos = vPos + TFHeight;
  1570.     chPos = GethPos(&Mesag6[0]);
  1571.     Move(WBRast,chPos,vPos);
  1572.     Text(WBRast,(STRPTR)Mesag6,strlen(Mesag6));
  1573.     vPos = vPos + TFHeight;
  1574.     chPos = GethPos(&Mesag7[0]);
  1575.     Move(WBRast,chPos,vPos);
  1576.     Text(WBRast,(STRPTR)Mesag7,strlen(Mesag7));
  1577. */
  1578.     vPos = vPos + 3*TFHeight/2;
  1579.  
  1580.     sprintf(&Mesag8[0],(STRPTR)"'Exploring the Julia Sets' is on the %d bit screen with palette option %d!",SDepth,PalOpt);
  1581.     chPos = GethPos(&Mesag8[0]);
  1582.     SetAPen(WBRast,1);
  1583.     Move(WBRast,chPos,vPos);
  1584.     Text(WBRast,(STRPTR)Mesag8,strlen(Mesag8));
  1585.  
  1586.     vPos = vPos + TFHeight;
  1587.     TmpPtr = &StrngBuffer[0];
  1588.  
  1589. /*    vPos = vPos + 3*TFHeight/2;
  1590.     chPos = GethPos(WBScreen->Title);
  1591.     SetFont(WBRast,BFont);
  1592.     SetAPen(WBRast,2);
  1593.     Move(WBRast,chPos,vPos);
  1594.     Text(WBRast,(STRPTR)WBScreen->Title,strlen(WBScreen->Title));
  1595.     if (NumColors <= 256)    Text(WBRast,"!",1);
  1596.     SetFont(WBRast,DFont);
  1597.     if (NumColors > 256)    {
  1598.         SetAPen(WBRast,1);
  1599.         sprintf(&MyStringBuf[0],", with palette option %d!",PalOpt);
  1600.         Text(WBRast,(STRPTR)MyStringBuf,strlen(MyStringBuf));
  1601.         } */
  1602. }
  1603.  
  1604. void LibsOpen()
  1605. {
  1606.     if (!DOSBase)    {
  1607.         DOSBase = (struct DosLibrary *)OpenLibrary((UBYTE *)"dos.library",0L);
  1608.         }
  1609.     DiskfontBase = (struct Library *)OpenLibrary((UBYTE *)"diskfont.library",0);
  1610.     GfxBase = (struct GfxBase *)OpenLibrary((UBYTE *)"graphics.library",0L);
  1611.  
  1612.     WarpBase = (struct Library *)OpenLibrary((UBYTE *)"powerpc.library",14L);
  1613.  
  1614.     IntuitionBase = (struct IntuitionBase *)OpenLibrary((UBYTE *)"intuition.library",0L);
  1615.     CyberGfxBase = (struct CyberGfxBase *)OpenLibrary((UBYTE *)"cybergraphics.library",40);
  1616. }
  1617.  
  1618. void LibsClose()
  1619. {
  1620.     if (WarpBase) CloseLibrary(WarpBase);
  1621.     if (DiskfontBase)    CloseLibrary(DiskfontBase);
  1622.  
  1623.     if (CyberGfxBase)    CloseLibrary((struct Library *)CyberGfxBase);
  1624.  
  1625.     if(GfxBase)            CloseLibrary((struct Library *)GfxBase);
  1626.  
  1627.     if(IntuitionBase)    CloseLibrary((struct Library *)IntuitionBase);
  1628.  
  1629.     }
  1630.  
  1631. void CheckMsg()
  1632. {
  1633. struct IntuiMessage *MyMsg;
  1634.     IMClass = 0;
  1635.     MyMsg = (struct IntuiMessage*) GetMsg(MyPort);
  1636.     if (MyMsg != NULL) {
  1637.           IMClass = MyMsg -> Class;
  1638.         ReplyMsg((struct Message *)MyMsg);
  1639.     }
  1640. }
  1641.  
  1642. void CheckIntMsg()
  1643. {
  1644. struct IntuiMessage *MyMsg;
  1645.     MenVal = 0;
  1646.     MyMsg = (struct IntuiMessage*) GetMsg(IntPort);
  1647.     if (MyMsg != NULL) {
  1648.         MenVal = MyMsg -> Code;
  1649.         IMClass = MyMsg -> Class;
  1650.         ReplyMsg((struct Message *)MyMsg);
  1651.     }
  1652. }
  1653.  
  1654. void ErrorDisplay()
  1655. {
  1656. static    char    Err020[]    = "You are running SMan on an Amiga without a math coprocessor!";
  1657. static    char    Err021[]    = "Although this is probably working, it must be incredibly slow!";
  1658. static    char    Err022[]    = "Please run SMan on an adequate machine!";
  1659. static    char    Err023[]    = "Use the Close Gadget to Terminate.";
  1660.     SetRast(WBRast,0);
  1661.     SetAPen(WBRast,1);
  1662.     Move(WBRast,40,80);
  1663.     Text(WBRast,(STRPTR)Err020,strlen(Err020));
  1664.     Move(WBRast,40,95);
  1665.     Text(WBRast,(STRPTR)Err021,strlen(Err021));
  1666.     Move(WBRast,40,125);
  1667.     Text(WBRast,(STRPTR)Err022,strlen(Err022));
  1668.     SetAPen(WBRast,3);
  1669.     Move(WBRast,40,155);
  1670.     Text(WBRast,(STRPTR)Err023,strlen(Err023));
  1671.     WindowToFront(InfoWindow);
  1672.     IMClass = 0;
  1673.     while (IMClass != CLOSEWINDOW)    {
  1674.         CheckMsg();
  1675.         Delay(1);
  1676.         }
  1677. }
  1678.  
  1679. void CountChange()
  1680. {
  1681.     if((MenVal & 0xff) == 1)    MaxCnt = MaxCnt + 8;
  1682.     if((MenVal & 0xff) == 0x21)    MaxCnt = MaxCnt - 8;
  1683.     if((MenVal & 0xff) == 0x41)    MaxCnt = 2*MaxCnt;
  1684.     if((MenVal & 0xff) == 0x61) MaxCnt = MaxCnt/2;
  1685.     if (MaxCnt < 8)    MaxCnt = 8;
  1686.     WriteStuff();
  1687.     ActivateWindow(IntWindow);
  1688. }
  1689.  
  1690. void Restore(void)
  1691. {
  1692.     Factor = LastFactor;
  1693.     DX = 1./Factor;
  1694.     XCenter = LastX;
  1695.     YCenter = LastY;
  1696.     MenVal = 0xf820;    /* Force Redraw! */
  1697. }
  1698.  
  1699. void DrawPoly(void)
  1700. {
  1701. UWORD    xS,yS,xE,yE;
  1702.     PolyPnt = &PolyTab[0];
  1703.     xS = *PolyPnt++;
  1704.     yS = *PolyPnt++;
  1705.     xE = *PolyPnt++;
  1706.     yE = *PolyPnt++;
  1707.     LineToggle(xS,yS,xE,yE);
  1708.     xS = xE;
  1709.     yS = yE;
  1710.     xE = *PolyPnt++;
  1711.     yE = *PolyPnt++;
  1712.     LineToggle(xS,yS,xE,yE);
  1713.     xS = xE;
  1714.     yS = yE;
  1715.     xE = *PolyPnt++;
  1716.     yE = *PolyPnt++;
  1717.     LineToggle(xS,yS,xE,yE);
  1718.     xS = xE;
  1719.     yS = yE;
  1720.     xE = *PolyPnt++;
  1721.     yE = *PolyPnt++;
  1722.     LineToggle(xS,yS,xE,yE);
  1723. }
  1724.  
  1725. void PolyUpDate(void)
  1726. {
  1727.     PolyPnt = &PolyTab[0];
  1728.     x2 = IntWindow -> MouseX;
  1729.     *PolyPnt++ = x1;        /* Upper-Left Corner */
  1730.     *PolyPnt++ = y1;
  1731.     *PolyPnt++ = x2;        /* Upper-Right Corner */
  1732.     *PolyPnt++ = y1;
  1733.     DeltaX = x2 - x1;
  1734.     DeltaY = WHeight*DeltaX/WWidth;
  1735.     y2 = y1 + DeltaY;
  1736.     *PolyPnt++ = x2;        /* Lower-Right Corner */
  1737.     *PolyPnt++ = y2;
  1738.     *PolyPnt++ = x1;        /* Lower-Left Corner */
  1739.     *PolyPnt++ = y2;
  1740.     *PolyPnt++ = x1;        /* Upper-Left Corner */
  1741.     *PolyPnt++ = y1;
  1742.     Move(CWRast,x1,y1);
  1743.     PolyPnt = &PolyTab[0];
  1744.     DrawPoly();
  1745. }
  1746.  
  1747. /* Clear by reversing again */
  1748. void PolyClear(void)
  1749. {
  1750.     PolyPnt = &PolyTab[0];
  1751.     DrawPoly();
  1752. }
  1753. /*WaitChg will wait until there is at least a difference of 10 between
  1754.  the original MouseX value and the new. */
  1755.  
  1756. void WaitChg(void)
  1757. {
  1758.     while ((x2 - x1) < 5)    {
  1759.         x2 = IntWindow -> MouseX;
  1760.         Delay(1);
  1761.         }
  1762. }
  1763. void DoZoom(void)
  1764. {
  1765. double Ratio;
  1766.     x1 = 0;
  1767.     y1 = 0;
  1768.     x2 = 0;
  1769.     y2 = 0;
  1770.     while (MenVal != SELECTDOWN)    {
  1771.         x1 = IntWindow -> MouseX;
  1772.         y1 = IntWindow -> MouseY;
  1773.         CheckIntMsg();
  1774.         }
  1775.     x1 = IntWindow -> MouseX;
  1776.     y1 = IntWindow -> MouseY;
  1777.  
  1778. /* Now prep for complementary polygon (i.e. rectangle) */
  1779.     SetDrMd(CWRast,2);
  1780.     WaitChg();
  1781.     PolyUpDate();
  1782.     while (MenVal != SELECTUP)    {
  1783.         CheckIntMsg();
  1784.         PolyClear();
  1785.         PolyUpDate();
  1786.         Delay(1);
  1787.         }
  1788. /* Clear Polygon and restore drawing mode */
  1789.     PolyClear();
  1790.     SetDrMd(CWRast,0);
  1791.     LastFactor = Factor;
  1792.     LastX = XCenter;
  1793.     LastY = YCenter;
  1794.  
  1795.     Ratio = XWidth/DeltaX;
  1796.     Factor = Ratio*Factor;
  1797.     DX = 1./Factor;
  1798.     XCenter = XCenter - (double)(x1 - BLeft);
  1799.     XCenter = Ratio*XCenter;
  1800.     YCenter = YCenter - (double)(y1 - BTop);
  1801.     YCenter = Ratio*YCenter;
  1802.     MenVal = 0xf820;
  1803. }
  1804.  
  1805.  
  1806.  
  1807. void Zoom(void)
  1808. {
  1809.     xtemp = RightEdge;
  1810.     if ((MenVal & 0xf0) == 0xc0)    {
  1811.         PalOpt++;
  1812.         if (PalOpt > 5) PalOpt = 0;
  1813.         Palette32();
  1814.         }
  1815.  
  1816.     if((MenVal & 0xf0) == 0x00)    DoZoom();
  1817.     if(MenVal == 0xf822)    Restore();
  1818.     if((MenVal & 0xf0) == 0x40)    {
  1819.         --Power;
  1820.         if (PowerF == 0.)    {
  1821.             if (Power < 2) Power = 2;
  1822.             }
  1823.         else if (Power < 1) Power = 1;
  1824.         SetRast(WBRast,0);
  1825.         ActivateWindow(InfoWindow);
  1826.         }
  1827.     if((MenVal & 0xf0) == 0x60)    {
  1828.         Power++;
  1829.         if (Power > 99) {
  1830.             Power = 9;
  1831.             }
  1832.         SetRast(WBRast,0);
  1833.         ActivateWindow(InfoWindow);
  1834.         }
  1835.     if((MenVal & 0xf0) == 0x80)    {
  1836.         LastFactor = Factor;
  1837.         LastX = XCenter;
  1838.         LastY = YCenter;
  1839.         XCenter = 2.*(XCenter - HWidth);
  1840.         YCenter = 2.*(YCenter - HHeight);
  1841.         XCenter = XCenter + HWidth;
  1842.         YCenter = YCenter + HHeight;
  1843.         Factor = 2.*Factor;
  1844.         DX = 1./Factor;
  1845.         MenVal = 0xf820;
  1846.         }
  1847.     if((MenVal & 0xf0) == 0xa0)    {
  1848.         LastFactor = Factor;
  1849.         LastX = XCenter;
  1850.         LastY = YCenter;
  1851.         XCenter  = 0.5*(XCenter - HWidth);
  1852.         YCenter = 0.5*(YCenter - HHeight);
  1853.         XCenter = XCenter + HWidth;
  1854.         YCenter = YCenter + HHeight;
  1855.         Factor = Factor/2.;
  1856.         DX = 1./Factor;
  1857.         MenVal = 0xf820;
  1858.     }
  1859.     WriteStuff();
  1860. }
  1861.  
  1862.  
  1863. void SManMen(void)
  1864. {
  1865.         if (MenVal == 0xf800)    {
  1866.             WriteStuff();
  1867.             WBenchToFront();
  1868.             WindowToFront(InfoWindow);
  1869.             ActivateWindow(InfoWindow);
  1870.             }
  1871.         if (MenVal == 0xf840)    {
  1872.             SaveBMP();
  1873.             MenVal = 0;
  1874.             }
  1875.         if (MenVal == 0xf860)    {
  1876.             Save();
  1877.             MenVal = 0;
  1878.             }
  1879.         if (MenVal == 0xf880)    {
  1880.             SaveP();
  1881.             MenVal = 0;
  1882.             }
  1883.         if (MenVal == 0xf8a0)    {
  1884.             LoadP();
  1885.             MenVal = 0xf820;
  1886.             }
  1887. }
  1888.  
  1889.  
  1890.  
  1891. void FullCheck(void)
  1892. {
  1893. USHORT    SavVal;
  1894. ULONG    SavCls;
  1895.  
  1896. struct IntuiMessage *MyMsg;
  1897.         IMClass = 0;
  1898.         MenVal = 0;
  1899.         CheckMsg();
  1900.         if (IMClass == CLOSEWINDOW) {
  1901.             ScreenToFront(IntWindow->WScreen);
  1902.             WindowToFront(IntWindow);
  1903.             return;
  1904.             }
  1905.         CheckIntMsg();
  1906.         if (IMClass == CLOSEWINDOW) {
  1907.             ScreenToFront(IntWindow->WScreen);
  1908.             WindowToFront(IntWindow);
  1909.             MenVal = 0xf8c0;
  1910.             return;
  1911.             }
  1912.         if (MenVal)     {
  1913.             SavVal = MenVal;
  1914.             SavCls = IMClass;
  1915.             while (MenVal == MENUDOWN)    {    /*Was MENUPICK */
  1916.                 CheckIntMsg();
  1917.                 }
  1918.             MenVal = SavVal;
  1919.             IMClass = SavCls;
  1920.             if (SavVal == 0xffff)    {
  1921.                 MenVal = 0;
  1922.                 }
  1923.             }
  1924.         if (IMClass == IDCMP_NEWSIZE) {
  1925.             while (IMClass == IDCMP_NEWSIZE)    {
  1926.                 IMClass = 0;
  1927.                 MyMsg = (struct IntuiMessage*) GetMsg(IntWindow -> UserPort);
  1928.                 if (MyMsg)    {
  1929.                     IMClass = MyMsg -> Class;
  1930.                     ReplyMsg((struct Message *)MyMsg);
  1931.                     }
  1932.                 }
  1933.             GetWindowSize();
  1934.             MenVal = 0xf820;    /* Force a redraw */
  1935.             }
  1936.  
  1937.         if (MenVal & 0xf800) {
  1938.             if ((MenVal & 0xf) == 1) {
  1939.                 CountChange();
  1940.                 MenVal = 0;
  1941.                 }
  1942.             if ((MenVal & 0xf) == 3) PowerChange();
  1943.             if (MenVal == 0xf800)    {
  1944.                 WriteStuff();
  1945.                 WBenchToFront();
  1946.                 WindowToFront(InfoWindow);
  1947.                 ActivateWindow(InfoWindow);
  1948.                 MenVal = 0;
  1949.                 }
  1950.             if (MenVal == 0xf8c0) xtemp = RightEdge;    /* Quit */
  1951.             if (MenVal == 0xf840) xtemp = RightEdge;    /* Save BMP */
  1952.             if (MenVal == 0xf860) SaveIFF = TRUE;        /* Save iff */
  1953.             if (MenVal == 0xf880) xtemp = RightEdge;    /* SaveP */
  1954.             if (MenVal == 0xf8a0) xtemp = RightEdge;    /* LoadP */
  1955.             if ((MenVal & 0xf80f) == 0xf802) xtemp = RightEdge;    /* Zoom */
  1956.             if ((MenVal & 0xf820) == 0xf820) xtemp = RightEdge; /* Redraw */
  1957.             }
  1958. }
  1959.  
  1960.  
  1961.  
  1962. void PlotIt(UWORD Color)
  1963. {
  1964. ULONG *ColSrc;
  1965. UWORD Clr;
  1966. int BotCol,TopCol;
  1967.     Clr = Color & 0xffff;
  1968.     if (Clr != 0xffff)    {
  1969.         if (Clr > LastMax) {
  1970.             LastMax = Clr;
  1971. /*            DisCnt();*/
  1972.             }
  1973.         }
  1974.         if (NumColors == 16)    {
  1975.             BotCol = 0;
  1976.             TopCol = 15;
  1977.             }
  1978.         else {
  1979.             BotCol = 4;
  1980.             TopCol = NumColors - 1;
  1981.             }
  1982.         if (Clr == 0xffff) {
  1983.                    Clr = TopCol;
  1984.             }
  1985.         else if (Color > (TopCol - BotCol)) {
  1986.                 while (Clr > (TopCol - BotCol)) Clr = Clr - (TopCol - BotCol);
  1987.                 }
  1988.         if (Clr != TopCol) Clr  = Clr + BotCol;
  1989.         if (Clr == 17) Clr = 20;
  1990.         if (Clr == 18) Clr = 21;
  1991.         if (Clr == 19) Clr = 22;
  1992.  
  1993.         *PixelBuf++ = (UBYTE)(Clr & 0xff);
  1994. }
  1995.  
  1996.  
  1997. void GetWindowSize(void)
  1998. {
  1999. WORD OldWidth,OldHeight;
  2000.     OldWidth = WWidth;
  2001.     OldHeight = WHeight;
  2002.     BLeft = (LONG)IntWindow->BorderLeft;
  2003.     BTop = (LONG)IntWindow->BorderTop;
  2004.     RightEdge = IntWindow->GZZWidth;
  2005.     FarEdge = IntWindow->GZZHeight;
  2006.     WWidth = RightEdge;
  2007.     WHeight = FarEdge;
  2008.     XWidth = WWidth;
  2009.     XHeight = WHeight;
  2010.     XC = RightEdge/2;
  2011.     YC = FarEdge/2;
  2012.     HWidth = XC;
  2013.     HHeight = YC;
  2014.     XCenter = XCenter + 0.5*(double)(WWidth - OldWidth);
  2015.     YCenter = YCenter + 0.5*(double)(WHeight - OldHeight);
  2016.     WriteStuff();
  2017. }
  2018.  
  2019. void PowerChange()
  2020. {
  2021.     if ((MenVal & 0xf0) == 0) {
  2022.         DeltaP = 0.1;
  2023.         }
  2024.     if ((MenVal & 0xf0) == 0x20) {
  2025.         DeltaP = 0.0;
  2026.         PowerF = 0.;
  2027.         }
  2028.     if ((MenVal & 0xf0) == 0x40) {
  2029.         DeltaP = DeltaP/10.;
  2030.         if (DeltaP < 1.e-14) DeltaP = 1.e-14;
  2031.         }
  2032.     if ((MenVal & 0xf0) == 0x60) {
  2033.         DeltaP = 10.0*DeltaP;
  2034.         if (DeltaP > 0.1) DeltaP = 0.1;
  2035.         }
  2036.     if ((MenVal & 0xf0) == 0x80) {
  2037.         PowerF = PowerF + DeltaP;
  2038.         if (PowerF >= 1.0)    {
  2039.             PowerF = PowerF - 1.0;
  2040.             Power++;
  2041.             if (Power > 99) Power = 9;
  2042.             xtemp = RightEdge;
  2043.             }
  2044.         }
  2045.     if ((MenVal & 0xf0) == 0xa0) {
  2046.         PowerF = PowerF - DeltaP;
  2047.         if (PowerF < 0.)    {
  2048.             --Power;
  2049.             PowerF = PowerF + 1.0;
  2050.             if (Power < 1) {
  2051.                 Power = 1;
  2052.                 }
  2053.             }
  2054.         }
  2055.     SetRast(WBRast,0);
  2056.     ActivateWindow(InfoWindow);
  2057.     WriteStuff();
  2058.     ActivateWindow(IntWindow);
  2059.     MenVal = 0;
  2060. }
  2061.  
  2062. int LineCheck(void)
  2063. {
  2064.         CheckMsg();
  2065.         if (IMClass == CLOSEWINDOW)    {
  2066.             ScreenToFront(IntWindow->WScreen);
  2067.             WindowToFront(IntWindow);
  2068.             ActivateWindow(IntWindow);
  2069.             }
  2070.         if ((!MenVal) && (!IMClass)) CheckIntMsg();
  2071.         if (MenVal)    {
  2072.             if ((MenVal & 0xf) == 1)    CountChange();
  2073.             if (MenVal == 0xf8c0)    return(TRUE);
  2074.             if ((MenVal & 0xf) == 2) {
  2075.                 Zoom();
  2076.                 if (MenVal == 0xf820) return(TRUE);
  2077.                 }
  2078.             if ((MenVal & 0xf) == 0)    {
  2079.                 SManMen();
  2080.                 if((MenVal & 0xff) == 0x20)    return(TRUE);
  2081.                 }
  2082.             if ((MenVal & 0xf) == 3) PowerChange();
  2083.             }
  2084. }
  2085.  
  2086.  
  2087. void WritePixels(ULONG *MyPixelBuf,ULONG Width,ULONG Height)
  2088. {
  2089. APTR fpp;
  2090. ULONG NumPixels,BaseAdr,xOff,yOff,xyOff,xLoc,yLoc;
  2091. ULONG *DstBuf,*LastBase;
  2092.     NumPixels = Width*Height;
  2093. /*    fpp =
  2094. LockBitMapTags(&WBScreen->BitMap,LBMI_BASEADDRESS,&BaseAdr,TAG_DONE);*/
  2095.     BaseAdr = 0xe0000000;
  2096.     xOff = IntWindow->LeftEdge + IntWindow->BorderLeft;
  2097.     yOff = IntWindow->TopEdge + IntWindow->BorderTop;
  2098.     yOff = yOff*WBScreen->Width;
  2099.     xyOff = xOff + yOff;
  2100.     DstBuf = (ULONG *)BaseAdr + xyOff;
  2101.     LastBase = DstBuf;
  2102.     yLoc = 0;
  2103.     while (yLoc < Height)    {
  2104.         xLoc = 0;
  2105.         while (xLoc < Width)    {
  2106.             *DstBuf++ = *MyPixelBuf++;
  2107.             xLoc++;
  2108.             }
  2109.         yLoc++;
  2110.         DstBuf = LastBase + WBScreen->Width;
  2111.         LastBase = DstBuf;
  2112.         }
  2113. /*     if (fpp) UnLockBitMap(fpp);*/
  2114. }
  2115.  
  2116. void GreyPixels(ULONG *MyPixelBuf,ULONG Width,ULONG Height)
  2117. {
  2118. ULONG NumPixels,PixCnt;
  2119.     NumPixels = Width*Height;
  2120.     PixCnt = 0;
  2121.     while (PixCnt < NumPixels)    {
  2122.         *MyPixelBuf++ = 0xaaaaaa;
  2123.         PixCnt++;
  2124.         }
  2125. }
  2126.  
  2127.  
  2128. /* Note that some of the input checking doesn't appear to work.
  2129. This problem is yet to be chased down. */
  2130.  
  2131. BOOL InputCheck(void)
  2132. {
  2133. UWORD RBVal;
  2134. UBYTE Val1,Val2;
  2135.     *DDRAV = 3;
  2136.     Val1 = *SDRV;
  2137.     if (Val1) *SDRV = 0;
  2138.     if (Val1 == 0x31) {
  2139.         return(TRUE);
  2140.         }
  2141. /* Check for left mouse button! */
  2142.     Val2 = *PDRAAV;
  2143.     if (!(Val2 & 0x40)) {
  2144.         return(TRUE);
  2145.         }
  2146.         RBVal = ((*POTGOR)& 0x400);
  2147.     if (RBVal != 0x400) {
  2148.         return(TRUE);
  2149.         }
  2150.     return(FALSE);
  2151. }
  2152.  
  2153.  
  2154. void FullSurface()
  2155. {
  2156. double yRel;
  2157. UWORD BorLft,BorTop;
  2158. BOOL IPCheck;
  2159. int RepCntr;
  2160.  
  2161.      BorLft = IntWindow->BorderLeft;
  2162.     BorTop = IntWindow->BorderTop;
  2163.     ytemp = NearEdge;
  2164.     Limit = Two*Factor;
  2165.     Limit = Limit*Limit;
  2166.     PixelBuf = WindowBuf;
  2167.     LPixelBuf = (ULONG *)PixelBuf;
  2168.     PowerN = (double)Power + PowerF;
  2169.     GetSysTime(&CurTime);
  2170.     Secs = CurTime.tv_secs;
  2171.     Micros = CurTime.tv_micro;
  2172.     while (ytemp < FarEdge)    {
  2173.         yRel = (double)ytemp - YCenter;
  2174.         yRel = yRel*DX;
  2175.         if ((PowerF != 0.)||(Power > 7)) FncFnd(yRel);
  2176.         if ((Power == 2)&&(PowerF == 0.))    {
  2177.             UseLibP2(yRel);
  2178.             }
  2179.  
  2180.         if ((Power == 3)&&(PowerF == 0.))    {
  2181.             UseLibP3(yRel);
  2182.             }
  2183.  
  2184.  
  2185.         if ((Power == 4)&&(PowerF == 0.))    {
  2186.             UseLibP4(yRel);
  2187.             }
  2188.  
  2189.         if ((Power == 5)&&(PowerF == 0.))    {
  2190.             UseLibP5(yRel);
  2191.             }
  2192.  
  2193.         if ((Power == 6)&&(PowerF == 0.))    {
  2194.             UseLibP6(yRel);
  2195.             }
  2196.  
  2197.         if ((Power == 7)&&(PowerF == 0.))    {
  2198.             UseLibP7(yRel);
  2199.             }
  2200.  
  2201.         IPCheck = FALSE;
  2202.         IPCheck = InputCheck();
  2203.         if (IPCheck)    {
  2204.             FullCheck();
  2205.                    if (!IMClass && !MenVal) CheckMsg();
  2206.             if (IMClass == CLOSEWINDOW)    {
  2207.                 ScreenToFront(IntWindow->WScreen);
  2208.                 WindowToFront(IntWindow);
  2209.                 ActivateWindow(IntWindow);
  2210.                 }
  2211.             if ((!MenVal) && (!IMClass)) CheckIntMsg();
  2212.             if (MenVal)    {
  2213.                 if ((MenVal & 0xf) == 1)    CountChange();
  2214.                 if (MenVal == 0xf8c0)    ytemp = FarEdge;
  2215.                 if ((MenVal & 0xf) == 2) {
  2216.                     Zoom();
  2217.                     if (MenVal == 0xf820) return;
  2218.                     }
  2219.                 if ((MenVal & 0xf) == 0)    {
  2220.                     SManMen();
  2221.                     if((MenVal & 0xff) == 0x20)    return;
  2222.                     }
  2223.                 if ((MenVal & 0xf) == 3) PowerChange();
  2224.             }
  2225.         }
  2226.     if (NumColors <= 256)    {
  2227.         WritePixelLine8(IntWindow->RPort,BorLft,BorTop+ytemp,WWidth,WindowBuf,&MainWRast);
  2228.         PixelBuf = WindowBuf;
  2229.             }
  2230.         ytemp++;
  2231.         if ((ytemp & 0x3f)== 0) {
  2232.              if (MaxCnt > 256) DisCnt();
  2233.             }
  2234.     }
  2235.     GetSysTime(&CurTime);
  2236.     if (CurTime.tv_micro < Micros)    {
  2237.         CurTime.tv_micro = CurTime.tv_micro + 1000000;
  2238.         CurTime.tv_secs = CurTime.tv_secs - 1;
  2239.         }
  2240.     ElTime = CurTime.tv_secs - Secs + (CurTime.tv_micro - Micros)/1000000.;
  2241.  
  2242.     if (NumColors > 256)    {
  2243.         WritePixelArray((APTR*)WindowBuf,0,0,4*WWidth,IntWindow->RPort,BorLft,BorTop,WWidth,WHeight,RECTFMT_ARGB);
  2244.         LPixelBuf = (ULONG *)WindowBuf;
  2245.         }
  2246.     SetAPen(WBRast,1);
  2247.     sprintf(&MyStringBuf[0],"Time to generate last complete image was %e seconds.",ElTime);
  2248.     Move(WBRast,20,InfoWindow->Height - 20);
  2249.     Text(WBRast,(STRPTR)&MyStringBuf[0],strlen(MyStringBuf));
  2250.     MenVal = 0;
  2251.     IMClass = 0;
  2252. }
  2253.  
  2254. void Status()
  2255. {
  2256. struct IntuiMessage *MyMsg;
  2257.     IMClass = 0;
  2258.     MenVal = 0;
  2259.     while (!MenVal)    {
  2260.         Delay(1);
  2261.         CheckMsg();
  2262.         if (IMClass == CLOSEWINDOW)    {
  2263.             ScreenToFront(IntWindow->WScreen);
  2264.             WindowToFront(IntWindow);
  2265.             ActivateWindow(IntWindow);
  2266.             }
  2267.         if (!MenVal) CheckIntMsg();
  2268.         if (IMClass == CLOSEWINDOW) {
  2269.             MenVal = 0xf8c0;
  2270.             return;
  2271.             }
  2272.         if ((MenVal & 0xff7f) == 0x68) MenVal = 0;
  2273.         if (MenVal & 0xf800)    {
  2274.             if (MenVal == 0xffff) MenVal = 0;
  2275.             if ((MenVal & 0xf) == 0)    {
  2276.                 SManMen();
  2277.                 if (MenVal == 0xf800) MenVal = 0;
  2278.                 }
  2279.             if ((MenVal & 0xf) == 1)    CountChange();
  2280.             if ((MenVal & 0xf) == 2)    Zoom();
  2281.             if ((MenVal & 0xf) == 3) PowerChange();
  2282.             if (MenVal == 0xf840)    {
  2283.                 SaveBMP();
  2284.                 MenVal = 0;
  2285.                 }
  2286.             if (MenVal == 0xf860)    {
  2287.                 Save();
  2288.                 MenVal = 0;
  2289.                 }
  2290.             if (MenVal == 0xf880)    {
  2291.                 SaveP();
  2292.                 MenVal = 0;
  2293.                 }
  2294.             if (MenVal == 0xf8A0)    {
  2295.                 LoadP();
  2296.                 MenVal = 0xf820;    /* Force a redraw */
  2297.                 }
  2298.             }
  2299.         if (IMClass == IDCMP_NEWSIZE) {
  2300.             while (IMClass == IDCMP_NEWSIZE)    {
  2301.                 IMClass = 0;
  2302.                 MyMsg = (struct IntuiMessage*) GetMsg(IntWindow -> UserPort);
  2303.                 if (MyMsg)    {
  2304.                     IMClass = MyMsg -> Class;
  2305.                     ReplyMsg((struct Message *)MyMsg);
  2306.                     }
  2307.                 }
  2308.             GetWindowSize();
  2309.             MenVal = 0xf820;    /* Force a redraw */
  2310.             }
  2311.     }
  2312. }
  2313.  
  2314. void RestoreOrigColors()
  2315. {
  2316. UWORD *MyTable;
  2317. SHORT CCount;
  2318.     MyTable = OldColorTable;
  2319.     CCount = 0;
  2320.     while (CCount < NumColors) {
  2321.         MySetRGB(CCount,*MyTable++);
  2322.         CCount++;
  2323.         }
  2324. }
  2325.  
  2326. void MySetRGB(Color,Value)
  2327. SHORT Color;
  2328. USHORT Value;
  2329. {
  2330. UBYTE Red,Green,Blue;
  2331. USHORT SRed,SGreen,SBlue;
  2332.     SRed = Value;
  2333.     SRed >>=8;
  2334.     Red = (UBYTE)SRed;
  2335.     SGreen = 0xf0 & Value;
  2336.     SGreen >>=4;
  2337.     Green = (UBYTE)SGreen;
  2338.     SBlue = 0xf & Value;
  2339.     Blue = (UBYTE)SBlue;
  2340.     SETRGB(WBScreen,Color,Red,Green,Blue);
  2341. }
  2342.  
  2343.  
  2344. int CPUStuff(void)
  2345. {
  2346. static ULONG CPUTag[] = {
  2347.     GETINFO_CPU,0,
  2348.     GETINFO_PVR,0,
  2349.     GETINFO_BUSCLOCK,0,
  2350.     GETINFO_CPUCLOCK,0,
  2351.     TAG_DONE
  2352.     };
  2353. int StrLength;
  2354.     GetInfo((struct TagItem *)CPUTag);
  2355.     if (CPUTag[1] == 0) return(-1);
  2356.     if (CPUTag[1] & CPUF_603) sprintf(&CPUStrBuf[0],"603 ");
  2357.     if (CPUTag[1] & CPUF_603E) sprintf(&CPUStrBuf[0],"603e ");
  2358.     if (CPUTag[1] & CPUF_604) sprintf(&CPUStrBuf[0],"604 ");
  2359.     if (CPUTag[1] & CPUF_604E) sprintf(&CPUStrBuf[0],"604e ");
  2360.     if (CPUTag[1] & CPUF_620) sprintf(&CPUStrBuf[0],"620 ");
  2361.     StrLength = strlen(CPUStrBuf);
  2362.     sprintf(&CPUStrBuf[StrLength],"CPU at %#.1f MHz ",(double)(CPUTag[7]/1.e6));
  2363.     StrLength = strlen(CPUStrBuf);
  2364.     sprintf(&CPUStrBuf[StrLength],"with bus clock of %#.1f MHz. ",(double)(CPUTag[5]/1.e6));
  2365.     return(0);
  2366. }
  2367.  
  2368.  
  2369.  
  2370. int main(void)
  2371. {
  2372. ULONG WindowBufSize;
  2373. ULONG BMAttr,Time1Hi,Time2Hi,Time1Lo,Time2Lo;
  2374. double Freq,TotTic;
  2375. char    StrBuf[100];
  2376. int VPos,KeyCnt;
  2377. UWORD BorLft,BorTop;
  2378.  
  2379. UBYTE KeyVal;
  2380.  
  2381.     SDRV =    (UBYTE *)0xbfec01;
  2382.     DDRAV =    (UBYTE *)0xbfe201;
  2383.     PDRAAV = (UBYTE *)0xbfe001;
  2384.     POTGOR = (UWORD *)0xdff016;
  2385.     PalOpt = 3;
  2386.     Two = 2.;
  2387.     SaveIFF = FALSE;
  2388.     LastMax = 0;
  2389.     PowerF = 0.;
  2390.     DeltaP = 0.;
  2391.     WindowBuf = 0;
  2392.     SysFlag = SysBase -> AttnFlags;
  2393.     LibsOpen();
  2394.     MyTask = FindTaskPPC(0);
  2395.      CPUStuff();
  2396.     OpenTimer();
  2397.     Pi = 4.*atan(1.);
  2398.     TwoPi = 2.*Pi;
  2399.     PiD2 = Pi/2.;
  2400.     Power = 2;
  2401.     PowerN = 2.;
  2402.     CPU = 0;
  2403.     MaxCnt = 256;
  2404.     MaxCnt = 64;
  2405.     MltPlr = 0x80;
  2406.  
  2407.     WindowSet();
  2408.     if (SysFlag)    {
  2409.         SysFlag = SysBase -> AttnFlags;
  2410.         SWidth = 600;
  2411.         SHeight = 400;
  2412.         XC = SWidth/2;
  2413.         YC = SHeight/2;
  2414.         if (WBScreen->Width < 600) MltPlr = 0x40;
  2415.         Factor = (double)MltPlr;
  2416.         DX = 1./Factor;
  2417.         LastFactor = Factor;
  2418.         if (NumColors)    MaxCnt = NumColors;
  2419.         ScreenSet();
  2420.         WindowToFront(IntWindow);
  2421.          BorLft = IntWindow->BorderLeft;
  2422.         BorTop = IntWindow->BorderTop;
  2423.  
  2424.         if (NumColors > 256) MaxCnt = 256;
  2425.         if (NumColors <= 256) {
  2426.             WindowBufSize = WBScreen->Width*WBScreen->Height;
  2427.             WindowBuf = AllocMem(WindowBufSize,MemMode);
  2428.             VPos = ShowPalette();
  2429.             VPos = VPos - 100;
  2430.             }
  2431.         else {
  2432.             WindowBufSize = 4*WBScreen->Width*WBScreen->Height;
  2433.             WindowBuf = AllocMem(WindowBufSize,MemMode);
  2434.             GreyPixels((ULONG *)WindowBuf,(ULONG)WWidth,(ULONG)WHeight);
  2435.             VPos = 16 + ShowPicPalette();
  2436.             WritePixelArray((APTR*)WindowBuf,0,0,4*WWidth,IntWindow->RPort,BLeft,BTop,WWidth,WHeight,RECTFMT_ARGB);
  2437.             VPos = WHeight - 60;
  2438.             }
  2439.         MaxCnt = 32;
  2440.         SetFont(CWRast,CWFont);
  2441.         SetAPen(CWRast,1);
  2442.         Move(CWRast,10,VPos);
  2443.         VPos = VPos + 15;
  2444.         Move(CWRast,10,VPos);
  2445.         if (NumColors <= 256)    {
  2446.             VPos = 60;
  2447.             if(IntWindow->Width > 320)    {
  2448.                 sprintf(&StrBuf[0],"This display shows the %d colors of",PalSize);
  2449.                 Text(CWRast,&StrBuf[0],strlen(StrBuf));
  2450.                 VPos = VPos + 15;
  2451.                 Move(CWRast,10,VPos);
  2452.                 Text(CWRast,(STRPTR)"the palette being used for the",30);
  2453.                 VPos = VPos + 15;
  2454.                 Move(CWRast,10,VPos);
  2455.                 Text(CWRast,"Mandelbrot Images! The palette for",34);
  2456.                 VPos = VPos + 15;
  2457.                 Move(CWRast,10,VPos);
  2458.                 Text(CWRast,(STRPTR)"this screen may have changed, but will be",38);
  2459.                 VPos = VPos + 15;
  2460.                 Move(CWRast,10,VPos);
  2461.                 Text(CWRast,"restored when SMan is done!",27);
  2462.                 VPos = VPos + 15;
  2463.                 Move(CWRast,20,VPos);
  2464.                 }
  2465.             MWBitMap = (struct BitMap *)AllocBitMap((ULONG)WBScreen->Width,WBScreen->Height,WDepth,BMF_CLEAR|BMF_DISPLAYABLE,WBScreen->RastPort.BitMap);
  2466.             if (!MWBitMap) {
  2467.                 printf("Couldn't allocate the 1st BitMap!\n");
  2468.                 }
  2469.             InitRastPort(&MainWRast);
  2470.             MainWRast.Layer = NULL;
  2471.             MainWRast.BitMap = MWBitMap;
  2472.             Text(CWRast,(STRPTR)"Press Left Mouse Button to Continue!",36);
  2473.             OffMenu(IntWindow,0xf8c2);
  2474.         }
  2475.         else    {
  2476.             PalSize = 256;
  2477.  
  2478.             if (BPP > 1) {
  2479.                 OffMenu(IntWindow,0xf860);    /* Turn off Save Image (iff). */
  2480.                 PalSize = 0x8000;
  2481.                 if (SDepth >= 16) PalSize = 0x10000;
  2482.                 }
  2483.             VPos = VPos - 32;
  2484.             Move(CWRast,20,VPos);
  2485.             SetAPen(CWRast,2);
  2486.             sprintf(&StrBuf[0],"This display above shows some of the");
  2487.             Text(CWRast,&StrBuf[0],strlen(StrBuf));
  2488.  
  2489.             VPos = VPos + 15;
  2490.             Move(CWRast,20,VPos);
  2491.             sprintf(&StrBuf[0],"nearly %d colors of the palette",PalSize);
  2492.             Text(CWRast,&StrBuf[0],strlen(StrBuf));
  2493.  
  2494.             VPos = VPos + 15;
  2495.             Move(CWRast,20,VPos);
  2496.  
  2497.             Text(CWRast,(STRPTR)"used for the Mandelbrot Images!",31);
  2498.  
  2499.             VPos = VPos + 15;
  2500.             VPos = VPos + 15;
  2501.             Move(CWRast,20,VPos);
  2502.             SetAPen(CWRast,2);
  2503.             Text(CWRast,(STRPTR)"Press Left Mouse Button to Continue!",36);
  2504.         }
  2505.  
  2506.  
  2507.         MenVal = 0;
  2508.         while ((MenVal != SELECTDOWN)&&(MenVal != 0xf8c0)) {
  2509.              CheckIntMsg();
  2510.             if (IMClass == CLOSEWINDOW) MenVal = 0xf8C0;
  2511.              Delay(1);
  2512.             }
  2513.         XWidth = WWidth;
  2514.         XHeight = WHeight;
  2515.         HWidth = XC;
  2516.         XCenter = XC;
  2517.         HHeight = YC;
  2518.         YCenter = YC;
  2519.         LastX = XCenter;
  2520.         LastY = YCenter;
  2521.         WriteStuff();
  2522.         ActivateWindow(InfoWindow);
  2523.         MenVal = 0xf801;
  2524.         while (MenVal != 0xf8c0)    {
  2525.             FullSurface();
  2526.             while ((!MenVal) && (!IMClass))    {
  2527.                 Status();
  2528.                 }
  2529.             }
  2530.         }
  2531.     if (((SysFlag & AFF_68881)||(SysFlag & AFF_68882))&&((SysFlag & AFF_68020)||(SysFlag & AFF_68030))||(SysFlag & AFF_68040))    {
  2532.         BPP = BPP;
  2533.         }
  2534.     else {
  2535.         ErrorDisplay();
  2536.         }
  2537.     if (WBScreen->RastPort.BitMap->Depth >= 5) {
  2538.         WBScreen->ViewPort.ColorMap->ColorTable = OldColorTable;
  2539.         if (NumColors <= 256) RestoreOrigColors();
  2540.     }
  2541.     if (!WindowBuf) {
  2542.         if (MWBitMap) FreeBitMap(TmpBitMap);
  2543.         }
  2544.     Delay(25);
  2545.     if (NewColorTable)    {
  2546.         FreeMem(NewColorTable,TableSize);
  2547.         NewColorTable = 0;
  2548.         }
  2549.     if (WindowBuf) {
  2550.         FreeMem(WindowBuf,WindowBufSize);
  2551.         WindowBuf = 0;
  2552.         }
  2553.     ScreensClose();
  2554.     CloseTimer();
  2555.     LibsClose();
  2556.     return(0);
  2557. }
  2558.